CHGenerator/WebsiteGenerator/Files/ContentError.swift

28 lines
582 B
Swift
Raw Normal View History

2022-08-19 18:05:06 +02:00
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
}
}