Created
June 16, 2024 21:38
-
-
Save ABridoux/1df6957308a32955371fb9395a585780 to your computer and use it in GitHub Desktop.
OSStatus map to error
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// MARK: - Check error | |
extension OSStatus { | |
/// Error mapped from an `OSStatus`. | |
public struct StatusError: Error { | |
// MARK: Properties | |
let status: OSStatus | |
let message: String | |
} | |
/// Check an `OSStatus` to throw a `StatusError` if status is different from `noError`. | |
/// - Parameter message: Message of the error to be thrown. | |
/// - throws: If status is different from `noError`. | |
public func checkError(_ message: String) throws { | |
if self == noErr { return } | |
throw StatusError(status: self, message: message) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment