fix(wrangler): Fixed invalid command / argument error logging#12050
fix(wrangler): Fixed invalid command / argument error logging#12050
Conversation
🦋 Changeset detectedLatest 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 |
create-cloudflare
@cloudflare/kv-asset-handler
miniflare
@cloudflare/pages-shared
@cloudflare/unenv-preset
@cloudflare/vite-plugin
@cloudflare/vitest-pool-workers
@cloudflare/workers-editor-shared
@cloudflare/workers-utils
wrangler
commit: |
| if (hasHelpFlag && subCommand) { | ||
| const knownCommands = registry.topLevelCommands; | ||
| if (!knownCommands.has(subCommand)) { | ||
| logger.info(""); |
There was a problem hiding this comment.
This is here simply to appease formatting to match other errors by adding a spacing around the error.
This reverts commit 059bb56.
|
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 finished @NuroDev's task —— View job Changeset Review✅ All changesets look good The changeset
Cuteness ReportThis 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. |
dario-piotrowicz
left a comment
There was a problem hiding this comment.
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.
Merge commits are not allowed on this repository
Co-authored-by: Dario Piotrowicz <dario@cloudflare.com>
| 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}`); | ||
| } |
There was a problem hiding this comment.
🟡 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 includesfoo.toml)subCommand="foo.toml"- Since
"foo.toml"is not inknownCommands, the code throwsUnknown argument: foo.toml
Actual vs Expected
- Actual: Error "Unknown argument: foo.toml" is thrown
- Expected: Help for the
deploycommand 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.
Was this helpful? React with 👍 or 👎 to provide feedback.
Fixes #11823
Before
After
Before
After
A picture of a cute animal (not mandatory, but encouraged)