-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Fixed Wrangler invalid command / argument error logging #12050
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
NuroDev
wants to merge
10
commits into
main
Choose a base branch
from
NuroDev/fix-invalid-command-arg-errors
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+106
β12
Draft
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
0903a18
Added initial invalid command / flag fix
NuroDev 1ab388f
Added changeset
NuroDev 02364a9
Merge branch 'main' into NuroDev/fix-invalid-command-arg-errors
NuroDev 152acd8
Merge branch 'main' into NuroDev/fix-invalid-command-arg-errors
NuroDev 9e39b3f
Added empty line to unknown command with help flag
NuroDev 059bb56
Replaced `CommandLineArgsError` error with return statement
NuroDev 47cc108
Revert "Replaced `CommandLineArgsError` error with return statement"
NuroDev 5e81523
Merge branch 'main' into NuroDev/fix-invalid-command-arg-errors
NuroDev 04e1372
Merge branch 'main' into NuroDev/fix-invalid-command-arg-errors
NuroDev 5f7cdff
Merge branch 'main' into NuroDev/fix-invalid-command-arg-errors
NuroDev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| --- | ||
| "wrangler": patch | ||
| --- | ||
|
|
||
| Fixed Wrangler's error handling for both invalid commands with and without the `--help` flag, ensuring consistent and clear error messages. | ||
|
|
||
| Additionally, it also ensures that if you provide an invalid argument to a valid command, Wrangler will now correctly display that specific commands help menu. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1725,6 +1725,7 @@ export function createCLIParser(argv: string[]) { | |
| // This set to false to allow overwrite of default behaviour | ||
| wrangler.version(false); | ||
|
|
||
| registry.registerLegacyCommand("cloudchamber"); | ||
| registry.registerLegacyCommandCategory("containers", "Compute & AI"); | ||
| registry.registerLegacyCommandCategory("pubsub", "Compute & AI"); | ||
|
|
||
|
|
@@ -1746,16 +1747,29 @@ export async function main(argv: string[]): Promise<void> { | |
|
|
||
| // Check if this is a root-level help request (--help or -h with no subcommand) | ||
| // In this case, we use our custom help formatter to show command categories | ||
| const isRootHelpRequest = | ||
| (argv.includes("--help") || argv.includes("-h")) && | ||
| argv.filter((arg) => !arg.startsWith("-")).length === 0; | ||
| const hasHelpFlag = argv.includes("--help") || argv.includes("-h"); | ||
| 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(""); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
| logger.error(`Unknown argument: ${subCommand}`); | ||
| await showHelpWithCategories(); | ||
| throw new CommandLineArgsError(`Unknown argument: ${subCommand}`); | ||
| } | ||
NuroDev marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| let command: string | undefined; | ||
| let metricsArgs: Record<string, unknown> | undefined; | ||
| let dispatcher: ReturnType<typeof getMetricsDispatcher> | undefined; | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why can't they all be moved to the registry ?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Most commands are registered with the registry, but a handful of others still use the
wrangler.command(...)system and we need to aggregate them both into a single source of truth.To keep this PR simple(r) and not break anything I didn't want to move them to the registry yet. It could be simple, but I'm still not extremely well versed in the CLI setup to know if legacy commands require something that the registry doesn't?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had a similar question on a PR from TK yesterday.
My opinion is that we should stop adding things in the wrong way(TM) and refactor first - unless there is an urgent need to do otherwise.
Having different code paths is also something that also impacts the other PR.
+100 to refactor before doing more changes that will make the needed refactor harder later.
/cc @MattieTK @petebacondarwin
edit: I think the following somehow proves my point:
Yes the current code is too complex.
What we should do is to simplify/unify it instead of making if more complex for the next one that will debug/edit it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
xref #12055 (comment)