... we get the following confusing error messages:
> ./my-app --port abc
pattern 'abc' not found
> ./my-app --port 1.5
pattern '1.5' does not match to the end
The problems:
The name of the argument being parsed is not included in the error message.
"pattern {value}" is incorrect; the pattern is what we are searching for, but we print the value we got instead. This could be changed to "pattern for {shape}" (accurate, but perhaps not super useful to the user if they don't know what the shape 'u' actually means). Ideally we would print both the value and the shape though, for example "value 'abc' does not match expected format ('u')".
The specialization of this struct for radix_16 has try/catch blocks to intercept the low-level exception from do_from_chars to convert them to better messages (e.g. "Failed to parse {value} as hexadecimal: {reason}"). But the default parse_number (and the one for radix_2) do not. Still, none of the functions (even radix_16 which tried harder) include the name of the argument that failed parsing.
Currently, if trying to parse an
'u'
-shaped integer... we get the following confusing error messages:
The problems:
'u'
actually means). Ideally we would print both the value and the shape though, for example "value 'abc' does not match expected format ('u')".It seems the issue could be here https://github.com/p-ranav/argparse/blob/af442b4da0cd7a07b56fa709bd16571889dc7fda/include/argparse/argparse.hpp#L246-L259
The specialization of this struct for
radix_16
hastry
/catch
blocks to intercept the low-level exception fromdo_from_chars
to convert them to better messages (e.g. "Failed to parse {value} as hexadecimal: {reason}"). But the defaultparse_number
(and the one forradix_2
) do not. Still, none of the functions (evenradix_16
which tried harder) include the name of the argument that failed parsing.