Skip to content

cli: handle Ctrl+C in interactive prompts cleanly#5301

Open
jamesbroadhead wants to merge 2 commits into
mainfrom
jb/aitools-install-ctrlc
Open

cli: handle Ctrl+C in interactive prompts cleanly#5301
jamesbroadhead wants to merge 2 commits into
mainfrom
jb/aitools-install-ctrlc

Conversation

@jamesbroadhead
Copy link
Copy Markdown
Contributor

Summary

  • Pressing Ctrl+C in any interactive prompt (e.g. databricks aitools install) used to surface as Error: user aborted (huh) or Error: ^C (cmdio TUI) and exit 1 — i.e. the same shape as a genuine failure.
  • Treat it as a deliberate cancel instead: print cancelled to stderr and exit 130, the POSIX 128 + SIGINT convention that shells (and git/kubectl/etc.) already use, so scripts can distinguish $? == 130 from a real error.
  • Centralized in cmd/root: a new IsInterrupted(err) recognises both cmdio.ErrInterrupted (renamed from the previously unexported errCtrlC) and huh.ErrUserAborted. main.go consults it to pick the exit code.

Test plan

  • go test ./cmd/root/ ./libs/cmdio/... ./cmd/aitools/ — added TestIsInterrupted (incl. wrapped errors via %w) and TestExecuteInterruptPrintsCancelled covering both error sentinels; pre-existing tests still pass.
  • go test ./cmd/... ./libs/cmdio/... — all green.
  • Manual: databricks aitools install, press Ctrl+C at the scope/agent prompt, confirm stderr shows cancelled and echo $? is 130.

This pull request and its description were written by Isaac.

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
@github-actions
Copy link
Copy Markdown
Contributor

Approval status: pending

/cmd/root/ - needs approval

Files: cmd/root/root.go, cmd/root/root_test.go
Suggested: @simonfaltum
Also eligible: @renaudhartert-db, @hectorcast-db, @parthban-db, @tanmay-db, @Divyansh-db, @tejaskochar-db, @mihaimitrea-db, @chrisst, @rauchy

/libs/cmdio/ - needs approval

Files: libs/cmdio/io.go, libs/cmdio/prompt.go, libs/cmdio/select.go
Suggested: @simonfaltum
Also eligible: @renaudhartert-db, @hectorcast-db, @parthban-db, @tanmay-db, @Divyansh-db, @tejaskochar-db, @mihaimitrea-db, @chrisst, @rauchy

General files (require maintainer)

Files: NEXT_CHANGELOG.md, main.go
Based on git history:

  • @pietern -- recent work in libs/cmdio/, ./, cmd/root/

Any maintainer (@andrewnester, @anton-107, @denik, @pietern, @shreyas-goenka, @simonfaltum, @renaudhartert-db) can approve all areas.
See OWNERS for ownership rules.

@eng-dev-ecosystem-bot
Copy link
Copy Markdown
Collaborator

eng-dev-ecosystem-bot commented May 21, 2026

Commit: 95b20c8

Run: 26256245787

- 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants