You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I could argue that Error subclasses are for things that the programmer should have prevented through proper coding but failed to do so. But this error seems to be correct code and a problem with the data. I could easily argue that this should be an API Exception rather than a programmer Error.
You're wrong 😉
At least on that line. Now, line 74 on the other hand ...
In line 69 it checks if the name the programmer passes in is one that the same programmer has defined in the parser options for the parser. If there is no defined option with that name, then it's not a name of an option at all.
The programmer can be expected to know the names of all options that the argument parser was configured with.
In line 74, an ArgumentError is thrown for a data issue
if (option.mandatory &&!_parsed.containsKey(name)) {
throwArgumentError('Option $name is mandatory.');
The option was defined, as required even, but the parsed result contains no data for it.
There are two possibilities here:
This can't happen, parsing would have thrown instead (which would be The Way!), but then it shouldn't be throwing an ArgumentError, just have an assert or throw an AssertionError.
It can happen, and then it should throw an Exception (and be documented as doing so) or have a different return value (also documented).
Issue title checks out, example off by 5 lines. I think that's close enough!
ArgumentError is an Error and thus supposed to be used for programmer errors.
ArgResults.operator[] throws ArgumentError on what should be a runtime error:
core/pkgs/args/lib/src/arg_results.dart
Line 69 in 61e6771
Am I wrong?
The text was updated successfully, but these errors were encountered: