80d3c08a93
- Move to global objects for files and validation - Only write changed files - Check images for changes before scaling - Simplify code
28 lines
582 B
Swift
28 lines
582 B
Swift
import Foundation
|
|
|
|
struct ContentError: Error {
|
|
|
|
let reason: String
|
|
|
|
let source: String
|
|
|
|
let error: Error?
|
|
}
|
|
|
|
extension Optional {
|
|
|
|
func unwrapped(or error: ContentError) throws -> Wrapped {
|
|
guard case let .some(value) = self else {
|
|
throw error
|
|
}
|
|
return value
|
|
}
|
|
|
|
func unwrapOrFail(_ reason: String, source: String, error: Error? = nil) throws -> Wrapped {
|
|
guard case let .some(value) = self else {
|
|
throw ContentError(reason: reason, source: source, error: error)
|
|
}
|
|
return value
|
|
}
|
|
}
|