Error Handling
FileStorageError
Enum representing errors from file storage operations:
public enum FileStorageError: Error, LocalizedError {
case directoryCreationFailed(Error)
case fileWriteFailed(Error)
case fileReadFailed(Error)
case fileNotFound(String)
case decodingFailed(Error)
case encodingFailed(Error)
} Error Cases
| Case | Wrapped Type | Description |
|---|---|---|
directoryCreationFailed | Error | Failed to create records directory structure |
fileWriteFailed | Error | Failed to write JSON file to disk |
fileReadFailed | Error | Failed to read existing file |
fileNotFound | String (path) | Requested file does not exist |
decodingFailed | Error | JSON parsing failed |
encodingFailed | Error | JSON serialization failed |
Localized Descriptions
All cases conform to LocalizedError with errorDescription:
case .directoryCreationFailed(let error):
return "Failed to create directory: \(error.localizedDescription)"
case .fileWriteFailed(let error):
return "Failed to write file: \(error.localizedDescription)"
case .fileReadFailed(let error):
return "Failed to read file: \(error.localizedDescription)"
case .fileNotFound(let path):
return "File not found: \(path)"
case .decodingFailed(let error):
return "Failed to decode data: \(error.localizedDescription)"
case .encodingFailed(let error):
return "Failed to encode data: \(error.localizedDescription)" Error Handling Pattern
Errors bubble up through the actor boundary and should be caught at the UI layer:
do {
let records = try await timeTrackingService.getTodayRecords()
} catch let error as FileStorageError {
// Handle specific storage errors
} catch {
// Handle unexpected errors
} Related
- 301-file-storage - FileStorageService where errors originate
- 303-time-tracking - TimeTrackingService propagates these errors