habitat icon indicating copy to clipboard operation
habitat copied to clipboard

CLI can panic on bad input

Open christophermaier opened this issue 6 years ago • 6 comments

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: https://github.com/habitat-sh/habitat/blob/dc65012e9ec9ef9fca4f7eed87265fff04429e6e/components/hab/src/main.rs#L261-L269

However, it looks like we get to that point because we failed to do anything in exec_subcommand_if_called, specifically here: https://github.com/habitat-sh/habitat/blob/dc65012e9ec9ef9fca4f7eed87265fff04429e6e/components/hab/src/main.rs#L1272-L1274

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)

christophermaier avatar Feb 14 '19 15:02 christophermaier

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

baumanj avatar Feb 14 '19 16:02 baumanj

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

christophermaier avatar Feb 14 '19 18:02 christophermaier

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.

raskchanky avatar Feb 14 '19 18:02 raskchanky

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[bot] avatar Apr 02 '20 21:04 stale[bot]

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[bot] avatar Aug 13 '22 05:08 stale[bot]

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.

stale[bot] avatar May 22 '23 06:05 stale[bot]