Skip to content

fix(wrangler): Fixed invalid command / argument error logging#12050

Merged
NuroDev merged 25 commits intomainfrom
NuroDev/fix-invalid-command-arg-errors
Jan 30, 2026
Merged

fix(wrangler): Fixed invalid command / argument error logging#12050
NuroDev merged 25 commits intomainfrom
NuroDev/fix-invalid-command-arg-errors

Conversation

@NuroDev
Copy link
Copy Markdown
Member

@NuroDev NuroDev commented Jan 22, 2026

Fixes #11823

Before

➜ wrangler foo --help
wrangler

COMMANDS
  wrangler docs [search..]        📚 Open Wrangler's command documentation in your browser

After

➜ wrangler foo --help

✘ [ERROR] Unknown argument: foo

wrangler

COMMANDS
  wrangler docs [search..]        📚 Open Wrangler's command documentation in your browser

Before

➜ ❯ wrangler types --hello

✘ [ERROR] Unknown argument: hello


wrangler

COMMANDS
  wrangler docs [search..]        📚 Open Wrangler's command documentation in your browser

After

➜ wrangler types --hello

✘ [ERROR] Unknown argument: hello


wrangler types [path]

📝 Generate types from your Worker configuration

  • Tests
    • Tests included/updated
    • Automated tests not possible - manual testing has been completed as follows:
    • Additional testing not necessary because:
  • Public documentation
    • Cloudflare docs PR(s):
    • Documentation not necessary because: Minor bug fix

A picture of a cute animal (not mandatory, but encouraged)

Screenshot 2026-01-22 at 3 38 35 pm
Open with Devin

@NuroDev NuroDev self-assigned this Jan 22, 2026
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Jan 22, 2026

🦋 Changeset detected

Latest commit: 3972091

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Jan 22, 2026

create-cloudflare

npm i https://pkg.pr.new/create-cloudflare@12050

@cloudflare/kv-asset-handler

npm i https://pkg.pr.new/@cloudflare/kv-asset-handler@12050

miniflare

npm i https://pkg.pr.new/miniflare@12050

@cloudflare/pages-shared

npm i https://pkg.pr.new/@cloudflare/pages-shared@12050

@cloudflare/unenv-preset

npm i https://pkg.pr.new/@cloudflare/unenv-preset@12050

@cloudflare/vite-plugin

npm i https://pkg.pr.new/@cloudflare/vite-plugin@12050

@cloudflare/vitest-pool-workers

npm i https://pkg.pr.new/@cloudflare/vitest-pool-workers@12050

@cloudflare/workers-editor-shared

npm i https://pkg.pr.new/@cloudflare/workers-editor-shared@12050

@cloudflare/workers-utils

npm i https://pkg.pr.new/@cloudflare/workers-utils@12050

wrangler

npm i https://pkg.pr.new/wrangler@12050

commit: 3972091

@NuroDev NuroDev changed the title Added initial invalid command / flag fix Fixed Wrangler invalid command / argument error logging Jan 22, 2026
@NuroDev NuroDev marked this pull request as ready for review January 22, 2026 15:57
@NuroDev NuroDev requested a review from a team as a code owner January 22, 2026 15:57
Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 1 potential issue.

View issue and 5 additional flags in Devin Review.

Open in Devin Review

Comment thread packages/wrangler/src/index.ts
if (hasHelpFlag && subCommand) {
const knownCommands = registry.topLevelCommands;
if (!knownCommands.has(subCommand)) {
logger.info("");
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is here simply to appease formatting to match other errors by adding a spacing around the error.

Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 1 new potential issue.

View issue and 5 additional flags in Devin Review.

Open in Devin Review

Comment thread packages/wrangler/src/index.ts Outdated
Comment thread packages/wrangler/src/core/CommandRegistry.ts
@NuroDev
Copy link
Copy Markdown
Member Author

NuroDev commented Jan 23, 2026

Spoke with @petebacondarwin yesterday about this and I'm going to put this PR on hold until #12055 is merged so this fix doesn't have to rely on legacy commands.

@claude
Copy link
Copy Markdown
Contributor

claude Bot commented Jan 28, 2026

Claude finished @NuroDev's task —— View job


Changeset Review

✅ All changesets look good

The changeset .changeset/dark-rocks-smoke.md is properly formatted:

  • Version type: patch ✅ (appropriate for bug fix)
  • Description quality: Clear explanation of what was fixed ✅
  • Markdown headers: None used ✅
  • Analytics: Not applicable ✅
  • Format: Follows the imperative style with good detail ✅

Cuteness Report

This is Snow Paws. Absolutely covered in winter's finest glitter and sporting those soulful amber eyes. Clearly just discovered that snow is wet and cold but remains optimistic about the situation. 14/10 would give all the treats.


@NuroDev NuroDev changed the title Fixed Wrangler invalid command / argument error logging fix(wrangler): Fixed Wrangler invalid command / argument error logging Jan 29, 2026
@NuroDev NuroDev changed the title fix(wrangler): Fixed Wrangler invalid command / argument error logging fix(wrangler): Fixed invalid command / argument error logging Jan 29, 2026
@NuroDev NuroDev marked this pull request as ready for review January 29, 2026 15:24
@NuroDev NuroDev enabled auto-merge January 29, 2026 15:48
Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 1 new potential issue.

View issue and 12 additional flags in Devin Review.

Open in Devin Review

Comment thread packages/wrangler/src/core/handle-errors.ts Outdated
Copy link
Copy Markdown
Member

@dario-piotrowicz dario-piotrowicz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally looks good to me 👍

Possibly I'd add a TODO comment or something like that around the legacy commands explaining why they haven't yet been updated and that we should do so.

Comment thread packages/wrangler/src/__tests__/index.test.ts
Comment thread packages/wrangler/src/__tests__/index.test.ts
Comment thread packages/wrangler/src/__tests__/index.test.ts
Comment thread packages/wrangler/src/core/handle-errors.ts Outdated
auto-merge was automatically disabled January 30, 2026 10:48

Merge commits are not allowed on this repository

@github-project-automation github-project-automation Bot moved this from Untriaged to Approved in workers-sdk Jan 30, 2026
Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 1 new potential issue.

View issue and 6 additional flags in Devin Review.

Open in Devin Review

Comment on lines +1888 to +1907
const nonFlagArgs = argv.filter((arg) => !arg.startsWith("-"));
const isRootHelpRequest = hasHelpFlag && nonFlagArgs.length === 0;

const { wrangler, showHelpWithCategories } = createCLIParser(argv);
const { wrangler, registry, showHelpWithCategories } = createCLIParser(argv);

if (isRootHelpRequest) {
await showHelpWithCategories();
return;
}

// Check for unknown command with a `--help` flag
const [subCommand] = nonFlagArgs;
if (hasHelpFlag && subCommand) {
const knownCommands = registry.topLevelCommands;
if (!knownCommands.has(subCommand)) {
logger.info("");
logger.error(`Unknown argument: ${subCommand}`);
await showHelpWithCategories();
throw new CommandLineArgsError(`Unknown argument: ${subCommand}`);
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Flag values are incorrectly identified as unknown commands when flags precede the command

When global flags like --config are placed before the command name, the flag's value is incorrectly identified as the subcommand.

Click to expand

Mechanism

The code at line 1888 filters argv using a simple string check !arg.startsWith("-") to identify positional arguments. This approach doesn't account for flag values that don't start with -.

For wrangler --config foo.toml deploy --help:

  • argv = ["--config", "foo.toml", "deploy", "--help"]
  • nonFlagArgs = ["foo.toml", "deploy"] (incorrectly includes foo.toml)
  • subCommand = "foo.toml"
  • Since "foo.toml" is not in knownCommands, the code throws Unknown argument: foo.toml

Actual vs Expected

  • Actual: Error "Unknown argument: foo.toml" is thrown
  • Expected: Help for the deploy command should be shown

Impact

This is a regression. Users who place global flags before the command name (which yargs normally supports) will now get confusing error messages about their config file paths being "unknown arguments" when using --help.

Recommendation: Consider using a smarter approach to identify the subcommand, such as: (1) skipping known global flag names and their values when filtering, (2) only considering the first argument that doesn't follow a known flag, or (3) using yargs' built-in parsing before this check.

Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 1 new potential issue.

View issue and 9 additional flags in Devin Review.

Open in Devin Review

Comment thread packages/wrangler/src/index.ts
@NuroDev NuroDev merged commit b05b919 into main Jan 30, 2026
37 checks passed
@NuroDev NuroDev deleted the NuroDev/fix-invalid-command-arg-errors branch January 30, 2026 12:00
@github-project-automation github-project-automation Bot moved this from Approved to Done in workers-sdk Jan 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Unknown Wrangler commands skip error messaging with a flag

4 participants