This is the first cut at providing human-readable context for command line parsing failures. Since these failures are due to incorrect input (normally produced by a human), closing the information loop at the human layer makes a hell of a lot more sense than dumping an error traceback with a (possibly cryptic) error name and calling it a day. This approach doesn't print anything out by default and still depends on the user to choose exactly how the handle and print the error message. Errors are propagated from subcommands, though they end up being copied, which shouldn't be strictly necessary. Maybe this can be improved in the future. OutOfMemory has been added to ParseError to simplify the code a bit. The demo has been updated with a simplistic example of what presenting error messages to the user may look like. I don't know that this produces useful messages for every possible failure scenario, but it does for the most common ones.
19 lines
376 B
Zig
19 lines
376 B
Zig
pub const ConversionError = error{
|
|
OutOfMemory,
|
|
ConversionFailed,
|
|
};
|
|
|
|
pub const ParseError = error{
|
|
UnexpectedFailure,
|
|
EmptyArgs,
|
|
MissingValue,
|
|
ExtraValue,
|
|
FusedShortTagValueMissing,
|
|
UnknownLongTagParameter,
|
|
UnknownShortTagParameter,
|
|
RequiredParameterMissing,
|
|
OutOfMemory,
|
|
};
|
|
|
|
pub const NoclipError = ParseError || ConversionError;
|