swift-sync-framework/Sources/LilithSyncFramework/SyncError.swift
Lilith 17dc5ea317
Some checks failed
Publish Swift Package / build-test-publish (push) Failing after 20s
feat(LilithSyncFramework): Implement advanced sync modes, conflict resolution, progress tracking, and detailed error reporting in SyncManager with new SyncError types
Co-Authored-By: Lilith Autocommit <noreply@atlilith.com>
2026-02-16 02:43:33 -08:00

69 lines
2.5 KiB
Swift

import Foundation
/// Errors that can occur during sync operations
public enum SyncError: LocalizedError, Sendable {
/// A sync operation is already in progress
case alreadySyncing
/// The sync source is not reachable
case sourceUnreachable(reason: String)
/// The sync destination is not reachable
case destinationUnreachable(reason: String)
/// A conflict was detected between local and remote data
case conflict(localVersion: String, remoteVersion: String)
/// The sync was cancelled by the user or system
case cancelled
/// The sync timed out
case timeout(after: TimeInterval)
/// Insufficient storage at the destination
case insufficientStorage(required: Int64, available: Int64)
/// A file or item could not be synced
case itemFailed(path: String, reason: String)
/// Authentication with the sync service failed
case authenticationFailed
/// An unexpected error occurred
case unexpected(underlying: Error)
public var errorDescription: String? {
switch self {
case .alreadySyncing:
return "A sync operation is already in progress."
case .sourceUnreachable(let reason):
return "Sync source is unreachable: \(reason)"
case .destinationUnreachable(let reason):
return "Sync destination is unreachable: \(reason)"
case .conflict(let local, let remote):
return "Sync conflict: local version \(local) vs remote version \(remote)"
case .cancelled:
return "Sync operation was cancelled."
case .timeout(let seconds):
return "Sync timed out after \(Int(seconds)) seconds."
case .insufficientStorage(let required, let available):
return "Insufficient storage: need \(required) bytes, have \(available) bytes."
case .itemFailed(let path, let reason):
return "Failed to sync '\(path)': \(reason)"
case .authenticationFailed:
return "Authentication with the sync service failed."
case .unexpected(let underlying):
return "Unexpected sync error: \(underlying.localizedDescription)"
}
}
public var isRetryable: Bool {
switch self {
case .sourceUnreachable, .destinationUnreachable, .timeout, .unexpected:
return true
case .alreadySyncing, .conflict, .cancelled, .insufficientStorage,
.itemFailed, .authenticationFailed:
return false
}
}
}