cli: handle Ctrl+C in interactive prompts cleanly#5301
Open
jamesbroadhead wants to merge 2 commits into
Open
Conversation
When the user pressed Ctrl+C in `databricks aitools install` (or any other huh/bubbletea-backed prompt), the CLI printed an unfriendly `Error: user aborted` / `Error: ^C` and exited 1. Treat the cancel as a deliberate user action: print `cancelled` and exit 130 (POSIX SIGINT convention), so shell scripts can distinguish a user cancel from a real failure. The detection covers both prompt families used by the CLI: cmdio's TUI prompts (now-exported `cmdio.ErrInterrupted`) and the huh forms under `cmd/aitools` (`huh.ErrUserAborted`). Main reads the new `root.IsInterrupted` predicate to pick the exit code. Co-authored-by: Isaac
Contributor
Approval status: pending
|
Collaborator
|
Commit: 95b20c8 |
- Revert drive-by slog.String → slog.Int change on the exit_code log
field so JSON-log consumers see the same wire format as before. The
refactor was unrelated to the Ctrl+C fix.
- Give interrupts their own Info log line ("cancelled execution") so
users running --log-level=info don't lose Ctrl+C visibility (it
previously fell into the default Info branch; the first pass folded
it into Debug with ErrAlreadyPrinted).
- Extract ExitCodeFor(err) as the single source of truth for the
process exit code. Execute and main.go now both go through it,
removing the two-switch divergence risk.
- Add TestExitCodeFor covering nil / random / ErrAlreadyPrinted /
interrupted (direct + wrapped) so the exit-130 contract is locked
in by a unit test.
- Broaden the changelog to mention databricks apps init (also a huh
caller) alongside aitools.
- Add a one-liner comment explaining the intentional precedence of
ErrAlreadyPrinted over interrupted in the print switch.
Co-authored-by: Isaac
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
databricks aitools install) used to surface asError: user aborted(huh) orError: ^C(cmdio TUI) and exit 1 — i.e. the same shape as a genuine failure.cancelledto stderr and exit 130, the POSIX128 + SIGINTconvention that shells (andgit/kubectl/etc.) already use, so scripts can distinguish$? == 130from a real error.cmd/root: a newIsInterrupted(err)recognises bothcmdio.ErrInterrupted(renamed from the previously unexportederrCtrlC) andhuh.ErrUserAborted.main.goconsults it to pick the exit code.Test plan
go test ./cmd/root/ ./libs/cmdio/... ./cmd/aitools/— addedTestIsInterrupted(incl. wrapped errors via%w) andTestExecuteInterruptPrintsCancelledcovering both error sentinels; pre-existing tests still pass.go test ./cmd/... ./libs/cmdio/...— all green.databricks aitools install, press Ctrl+C at the scope/agent prompt, confirm stderr showscancelledandecho $?is 130.This pull request and its description were written by Isaac.