CHGenerator/Sources/Generator/Files/ContentError.swift
2022-09-09 11:18:32 +02:00

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
}
}