Skip to content

Improve CLI error message for unknown options to dask worker (#9094)#9281

Open
ernestprovo23 wants to merge 2 commits into
dask:mainfrom
ernestprovo23:fix/9094-worker-cli-error-message
Open

Improve CLI error message for unknown options to dask worker (#9094)#9281
ernestprovo23 wants to merge 2 commits into
dask:mainfrom
ernestprovo23:fix/9094-worker-cli-error-message

Conversation

@ernestprovo23
Copy link
Copy Markdown
Contributor

Summary

Improves the error message users see when they pass an unknown option or stray positional argument to dask worker (and dask scheduler). Fixes #9094.

Motivation

dask_worker's click group is configured with ignore_unknown_options=True, so any unrecognized token gets passed through into preload_argv and is then caught in validate_preload_argv (distributed/preloading.py).

For dash-prefixed tokens the existing code already raises click.NoSuchOption, which produces a helpful "No such option: --foo" message. But for any non-dash stray value the user just got:

Error: Got unexpected extra arguments: (foo bar)

with no hint that --help lists the valid options or that --preload consumes everything to its right. After #9240 removed the deprecated --nprocs, the original MCVE in #9094 now hits the dash-prefixed branch and produces a good message — but the catch-all message remained the same misleading wall.

Changes

  • distributed/preloading.py — extended the click.UsageError message in validate_preload_argv to point users at --help and explain the --preload ordering rule. No structural changes; the NoSuchOption branch is untouched.
  • distributed/cli/tests/test_dask_worker.py — two new CliRunner tests:
    • test_unknown_option_reports_no_such_option — regression guard for the dash-prefixed branch.
    • test_stray_positional_hints_at_help_and_preload — asserts the improved message mentions --help and --preload.

Net diff: +26 / -1 across two files.

Testing

Repro on main after #9240:

$ dask worker tcp://127.0.0.1:8786 foo bar
Error: Got unexpected extra arguments: (foo bar)

After this PR:

$ dask worker tcp://127.0.0.1:8786 foo bar
Error: Got unexpected extra arguments: (foo bar). If you intended these as
values for a --preload module, list --preload before them. Otherwise check
spelling -- see '--help' for valid options.

Dash-prefixed unknowns still produce the click-native message:

$ dask worker tcp://127.0.0.1:8786 --nprocs 1
Error: No such option: --nprocs

Local runs:

  • pytest distributed/cli/tests/test_dask_worker.py -m "not slow" — 31 passed, 2 skipped (uvloop missing), 0 failed.
  • New tests pass.
  • pre-commit run --files distributed/preloading.py distributed/cli/tests/test_dask_worker.py — ruff, black, mypy all clean.

Notes:

  • validate_preload_argv is also imported by distributed/cli/dask_scheduler.py, so the improved message benefits both entry points. Behavior is unchanged.
  • No touching of ignore_unknown_options=True in cli/dask_worker.py — that's a deeper refactor and out of scope for the message fix requested in Dask worker CLI error message might be misleading #9094.

Fixes #9094.

@ernestprovo23 ernestprovo23 requested a review from fjetter as a code owner May 28, 2026 12:20
@github-actions
Copy link
Copy Markdown
Contributor

Unit Test Results

See test report for an extended history of previous test failures. This is useful for diagnosing flaky tests.

    31 files  +    1      31 suites  +1   10h 45m 18s ⏱️ + 43m 53s
 4 082 tests +    2   3 969 ✅ +    6    113 💤 +  1  0 ❌  - 3 
59 249 runs  +2 669  56 645 ✅ +2 553  2 604 💤 +122  0 ❌  - 4 

Results for commit a8b8572. ± Comparison against base commit bcad953.

This pull request skips 1 test.
distributed.deploy.tests.test_ssh ‑ test_defer_to_old

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Dask worker CLI error message might be misleading

1 participant