Skip to content
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

fix(cli) error gracefully when script arg is not present and --v8-flags is present in deno run #20145

Merged
merged 2 commits into from Aug 13, 2023

Conversation

cyradotpink
Copy link
Contributor

@cyradotpink cyradotpink commented Aug 13, 2023

Fix #20022, fix #19627 (duplicate)

#17333 upgraded clap from version 3.1 to version 4. clap version 3.2.0 (intentionally) broke a behavior that deno was relying on to make deno run --v8-flags=--help work without specifying a file, see clap-rs/clap#3793. The workaround was to make the script argument required unless --v8-flags is present. This broke the expectation that all successfully parsed run commands have the script argument set, leading to the panic on matches.remove_many::<String>("script_arg").unwrap().

Clap, as far as I was able to find out, does not currently offer a neat solution to this problem. This PR adds logic to create and return a custom clap error when a parsed run command does not have the script argument.

I added an appropriate test.

@crowlKats
Copy link
Member

crowlKats commented Aug 13, 2023

Thanks for looking into this. I was taking a look the other week hoping to find some proper solution and trying to avoid this, but now with the context of the clap PR, I see that this isn't currently possible to be handled properly.
I also just noticed clap-rs/clap#3838 and left a comment.
For now this seems the best solution, so lets go with it

@cyradotpink
Copy link
Contributor Author

I also spent much longer than I'd like to admit looking for the correct way to do this with clap 🙃 thanks for the review!

@crowlKats crowlKats merged commit ca9ba87 into denoland:main Aug 13, 2023
13 checks passed
@cyradotpink cyradotpink deleted the fix-cli-run-panic-v8flags-2 branch August 13, 2023 02:06
littledivy pushed a commit to littledivy/deno that referenced this pull request Aug 21, 2023
…ags` is present in `deno run` (denoland#20145)

Fix denoland#20022, fix denoland#19627 (duplicate)

denoland#17333 upgraded clap from version 3.1 to version 4. clap version 3.2.0
(intentionally) broke a behavior that deno was relying on to make `deno
run --v8-flags=--help` work without specifying a file, see
clap-rs/clap#3793. The workaround was to make the script argument
required _unless_ `--v8-flags` is present. This broke the expectation
that all successfully parsed `run` commands have the script argument
set, leading to the panic on
`matches.remove_many::<String>("script_arg").unwrap()`.

Clap, as far as I was able to find out, does not currently offer a neat
solution to this problem. This PR adds logic to create and return a
custom clap error when a parsed run command does not have the script
argument.

I added an appropriate test.
littledivy pushed a commit that referenced this pull request Aug 21, 2023
…ags` is present in `deno run` (#20145)

Fix #20022, fix #19627 (duplicate)

#17333 upgraded clap from version 3.1 to version 4. clap version 3.2.0
(intentionally) broke a behavior that deno was relying on to make `deno
run --v8-flags=--help` work without specifying a file, see
clap-rs/clap#3793. The workaround was to make the script argument
required _unless_ `--v8-flags` is present. This broke the expectation
that all successfully parsed `run` commands have the script argument
set, leading to the panic on
`matches.remove_many::<String>("script_arg").unwrap()`.

Clap, as far as I was able to find out, does not currently offer a neat
solution to this problem. This PR adds logic to create and return a
custom clap error when a parsed run command does not have the script
argument.

I added an appropriate test.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants