-
Notifications
You must be signed in to change notification settings - Fork 366
Description
I have a custom error type that I'm throwing from my command:
enum Error: LocalizedError {
case foo
...
var localizedDescription: String {
switch self {
case .foo: return "foo error"
...
}
}
}
These all surface with code 1 in the shell. I'd like at least some of them to report specific codes so I can more easily respond to them.
I've seen there's ExitCode which I could throw instead but then I don't have a single Error tracking all error states anymore and I'd need to make the error printing local to the throwing location because ExitCode does not do any error logging:
print("error bar")
throw ExitCode(2)
Currently I can just throw and tweak all the error messages in my Error's localizedDescription.
I tried making my Error adopt RawRepresentable in the hopes it might pick up the raw values from there but it didn't.
Is there another way to attach specific codes to custom error types? Would it be possible to pick up error codes from RawRepresentable or some other error code protocol?