Repository navigation
fix(alias): run finish_command cleanup on typo error paths - #2307
Merged
Merged
Conversation
`wt step <typo>` and `wt <typo>` previously exited through `enhance_and_exit_error` → `process::exit(2)`, skipping `finish_command`'s diagnostic dump and ANSI-reset for shell integration. The same issue applied to `wt config alias show/dry-run <typo>` and was fixed on #2306 by returning `WorktrunkError::AlreadyDisplayed` so the error flows back through `handle_command_failure`. Apply the same fix to the other two typo surfaces. Split `enhance_and_exit_error` into a shared `print_enhanced_clap_error` helper plus a non-diverging `enhance_clap_error` that returns `AlreadyDisplayed` with clap's exit code. The pre-dispatch parse path in `parse_cli` keeps the diverging variant (no `finish_command` setup yet). Co-Authored-By: Claude <[email protected]>
worktrunk-bot
approved these changes
Apr 19, 2026
1 task done
max-sixty
added a commit
that referenced
this pull request
Apr 19, 2026
… sites (#2308) ## Summary Follow-up from #2306/#2307. Three surfaces all built the same clap `InvalidSubcommand` error with identical recipes (insert name + suggestions + usage context, render): - `wt <typo>` — `unrecognized_subcommand_error` (`src/commands/custom.rs`) - `wt step <typo>` — `unknown_step_command_error` (`src/commands/alias.rs`) - `wt config alias show/dry-run <typo>` — `unknown_alias_error` (`src/commands/config/alias.rs`) Consolidate into two shared helpers in `src/commands/mod.rs`: - `build_invalid_subcommand_error(anchor, name, suggestions) -> clap::Error` — builds the error with `InvalidSubcommand` / `SuggestedSubcommand` / `Usage` context populated. - `similar_subcommands(name, parent, alias_names) -> Vec<String>` — filters visible built-ins + alias names through `did_you_mean`. Moved from `custom.rs`; `unknown_step_command_error` used to re-implement this inline. `unknown_alias_error` keeps its unique `unrecognized subcommand` → `unrecognized alias` string rewrite and direct-print path, but delegates the clap error construction to the shared builder. Net: **-12 lines**, three near-duplicate recipes collapsed to one. All snapshots pass unchanged — the rendered output is identical. ## Test plan - [x] `cargo run -- hook pre-merge --yes` — all 3282 tests pass, lints clean, no snapshot drift Co-authored-by: Claude <[email protected]>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
wt step <typo>andwt <typo>previously exited throughenhance_and_exit_error→process::exit(2), skippingfinish_command's diagnostic dump and ANSI-reset for shell integration. The same issue applied towt config alias show/dry-run <typo>and was fixed on #2306 by returningWorktrunkError::AlreadyDisplayedso the error flows back throughhandle_command_failure. This PR applies the same fix to the other two typo surfaces.enhance_and_exit_errorinto a sharedprint_enhanced_clap_errorhelper plus a non-divergingenhance_clap_errorthat returnsAlreadyDisplayedwith clap's exit code.wt step <typo>(viaunknown_step_command_error) andwt <typo>(viahandle_custom_command) throughenhance_clap_error.parse_clikeeps the diverging variant (nofinish_commandsetup yet at that point).User-visible output is unchanged:
err.print()(called by the shared helper when no nested-subcommand tip applies) produces the same stderr content aserr.exit()minus the process exit, anderr.exit_code()returns 2 forInvalidSubcommanderrors.Test plan
cargo check --bin wtpassescargo clippy --bin wtcleannested_subcommand,step_aliasunrecognized cases)help::integration tests still pass — pre-dispatch parse path untouched🤖 Generated with Claude Code