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

CLI can panic on bad input #6157

Open
christophermaier opened this issue Feb 14, 2019 · 6 comments
Open

CLI can panic on bad input #6157

christophermaier opened this issue Feb 14, 2019 · 6 comments
Labels
Focus: CLI Related to the Habitat CLI (core/hab) component Stale Type: Bug Issues that describe broken functionality

Comments

@christophermaier
Copy link
Contributor

Example:

sudo hab sup ru 
thread 'main' panicked at 'internal error: entered unreachable code', components/hab/src/main.rs:269:18
note: Run with `RUST_BACKTRACE=1` for a backtrace.

I just got ahead of myself and hit Enter before I typed the "n" for "run".

This shouldn't be a panic; it should just give a usage error.

The cause of this specific panic can be found here:

("sup", Some(m)) => match m.subcommand() {
("depart", Some(m)) => sub_sup_depart(m)?,
("secret", Some(m)) => match m.subcommand() {
("generate", _) => sub_sup_secret_generate()?,
_ => unreachable!(),
},
// this is effectively an alias of `hab svc status`
("status", Some(m)) => sub_svc_status(m)?,
_ => unreachable!(),

However, it looks like we get to that point because we failed to do anything in exec_subcommand_if_called, specifically here:

// Delegate `hab sup run *` to the Launcher
("sup", "run", _) => command::launcher::start(ui, env::args_os().skip(2).collect()),
_ => Ok(()),

BUT NOTE! If you run hab sup runs, which is also not a command, you get an error message!

error: The subcommand 'runs' wasn't recognized
	Did you mean 'run'?

Something seems to be rather tangled up in our CLI processing here.

(This works on Habitat 0.74.0)

@baumanj
Copy link
Contributor

baumanj commented Feb 14, 2019

Removing this line defining aliases fixes it. I think we should remove it, as well as all the others. If users want to define their own aliases, that's simple for them to do, whereas baking in support for commands like

$ hab r k e

doesn't seem like good UX

@christophermaier
Copy link
Contributor Author

Ah, good find! Yeah, I kinda want to rip out most (if not all) the aliases.

@raskchanky
Copy link
Contributor

I agree with @baumanj. In addition, I think the existence of exec_subcommand_if_called is an anti-pattern. That caused a fair amount of headaches when implementing a certain feature. In my opinion, the idea that we deliberately circumvent the work that clap is doing, and do it ourselves, just so that we can exec a different process a little faster, is shooting ourselves in the foot and making things harder than they need to be.

@stale
Copy link

stale bot commented Apr 2, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. We value your input and contribution. Please leave a comment if this issue still affects you.

@stale stale bot added the Stale label Apr 2, 2020
@christophermaier christophermaier added Focus: CLI Related to the Habitat CLI (core/hab) component and removed A-cli labels Jul 24, 2020
@stale stale bot removed the Stale label Jul 24, 2020
@christophermaier christophermaier added Type: Bug Issues that describe broken functionality and removed C-bug labels Jul 24, 2020
@stale
Copy link

stale bot commented Aug 13, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. We value your input and contribution. Please leave a comment if this issue still affects you.

@stale stale bot added the Stale label Aug 13, 2022
@stale
Copy link

stale bot commented May 22, 2023

This issue has been automatically closed after being stale for 400 days. We still value your input and contribution. Please re-open the issue if desired and leave a comment with details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Focus: CLI Related to the Habitat CLI (core/hab) component Stale Type: Bug Issues that describe broken functionality
Projects
None yet
Development

No branches or pull requests

4 participants