Skip to content

A missing mandatory option crashes with a stack trace instead of printing the usage #42

Description

@riker-wamf

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

  1. Read each required option as nullable and validate it in the command, as search does. Explicit, and it gives each command a specific message.
  2. Catch ArgumentError in DartSlackCommandRunner.run and convert it to a usage error. One change covers every command, but the message stays generic.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions