Description
A command that declares an option mandatory: true does not report a missing option cleanly. It crashes with an unhandled Dart exception and a stack trace.
mandatory: true does not fail when the arguments are parsed. package:args throws an ArgumentError from ArgResults.[], which is the moment the command reads the option inside runAuthenticated. DartSlackCommandRunner.run catches FormatException and UsageException only, so the ArgumentError escapes to main.
Steps to reproduce
Measured on main at commit dfadc64:
$ dart run bin/dart_slack.dart history
Unhandled exception:
Invalid argument(s): Option channel is mandatory.
#0 ArgResults.[] (package:args/src/arg_results.dart:74:7)
#1 HistoryCommand.runAuthenticated (package:dart_slack/src/cli/commands/history_command.dart:38:32)
#2 AuthenticatedCommand.run (package:dart_slack/src/cli/commands/authenticated_command.dart:74:20)
#3 CommandRunner.runCommand (package:args/command_runner.dart:212:27)
#4 CompletionCommandRunner.runCommand (package:cli_completion/src/command_runner/completion_command_runner.dart:89:18)
#5 DartSlackCommandRunner.runCommand (package:dart_slack/src/cli/command_runner.dart:130:30)
#6 DartSlackCommandRunner.run (package:dart_slack/src/cli/command_runner.dart:74:20)
#7 main (file:///…/bin/dart_slack.dart:6:55)
Expected
The usage text, and exit code 64 (ExitCode.usage), the same as an invalid --limit value.
Affected commands
Every command that uses mandatory: true. grep -rn "mandatory: true" lib/ lists them.
Notes
Possible fixes
- Read each required option as nullable and validate it in the command, as
search does. Explicit, and it gives each command a specific message.
- Catch
ArgumentError in DartSlackCommandRunner.run and convert it to a usage error. One change covers every command, but the message stays generic.
Description
A command that declares an option
mandatory: truedoes not report a missing option cleanly. It crashes with an unhandled Dart exception and a stack trace.mandatory: truedoes not fail when the arguments are parsed.package:argsthrows anArgumentErrorfromArgResults.[], which is the moment the command reads the option insiderunAuthenticated.DartSlackCommandRunner.runcatchesFormatExceptionandUsageExceptiononly, so theArgumentErrorescapes tomain.Steps to reproduce
Measured on
mainat commitdfadc64:Expected
The usage text, and exit code 64 (
ExitCode.usage), the same as an invalid--limitvalue.Affected commands
Every command that uses
mandatory: true.grep -rn "mandatory: true" lib/lists them.Notes
Not logged ininstead. The crash needs a valid token orSLACK_TOKEN.searchcommand in feat: add full-text search command (search.messages) #37 avoids this. It reads--queryas a nullable value and prints the usage with exit 64. See PR feat: add full-text message search (search.messages) #43.Possible fixes
searchdoes. Explicit, and it gives each command a specific message.ArgumentErrorinDartSlackCommandRunner.runand convert it to a usage error. One change covers every command, but the message stays generic.