j-maly / CommandLineParser

Command line parser. Declarative arguments support. Rich set of argument types (switches, enums, files, etc...). Mutually exclusive arguments validations.
MIT License
137 stars 30 forks source link

Parse failure error should say which argument is failing #69

Open sebwills opened 4 years ago

sebwills commented 4 years ago

e.g. if I pass a non-numeric value to an integer argument, I currently get this:

   at System.Number.StringToNumber(ReadOnlySpan`1 str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal)
   at System.Number.ParseInt32(ReadOnlySpan`1 s, NumberStyles style, NumberFormatInfo info)
   at System.Int32.Parse(String s, IFormatProvider provider)
   --- End of inner exception stack trace ---
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at CommandLineParser.Arguments.ValueArgument`1.DefaultConvert(String stringValue)
   at CommandLineParser.Arguments.ValueArgument`1.Convert(String stringValue)
   at CommandLineParser.Arguments.ValueArgument`1.Parse(IList`1 args, Int32& i)
   at CommandLineParser.CommandLineParser.ParseCommandLine(String[] args)

The name of the argument is not mentioned, so it can be hard to know which argument is invalid.

It would be much more friendly if the error said something like "Failed to parse value 'xyz' for argument 'myArg': Input string was not in a correct format".