cli: properly handle exceptions
Metadata
Current evaluation
Merged a global exception handler for CLI errors, superseding PR #1429. Replaced per-command decorators to simplify maintenance and auto-coverage. Fixed exit_code property test failures before merge.
Suggested action: —
No scores available.
Issue body
This PR is an alternative to #1429. Instead of using click-specific decorators for every command, it simply installs a `sys.excepthandler` to deal properly with exceptions.
Advantages over #1429:
- Simpler
- Covers the store CLI with no additional work
- Covers future CLI additions automatically, nothing special needed
Disadvantages compared to #1429:
- Can no longer unit test CLI exit codes since the CLI is run within the same python process, the test catches the exception, and `excepthook` is never called. Integrations tests are needed instead.
- Global behavior can cause unexpected things to happen (i.e. the simple fact that some exceptions are masked by a global handler may be unexpected a year down the road when we add a new command)
Evaluation history
| Date | Model | Scores | Action | Summary |
|---|---|---|---|---|
| qwen/qwen3.6-35b-a3b | — | — | Merged a global exception handler for CLI errors, superseding PR #1429. Replaced per-command decorators to simplify maintenance and auto-coverage. Fixed exit_code property test failures before merge. | |
| qwen3.6-35b-a3b-mtp-q6 | — | — | Merged. Implements a global sys.excepthandler for CLI exception handling, superseding PR #1429. Includes an exception sweep, shifts exit code verification to integration tests, and addresses review feedback on property naming and commit structure. | |
| qwen3.6-35b-a3b-mtp-q6 | — | — | Merged a global sys.excepthandler for CLI exception handling, replacing a decorator-based alternative. The team preferred this simpler approach and agreed to test exit codes via integration tests. Fixed exit_code property test failures before merge. |
Update history
No update history recorded yet.
Related issues
| Issue | Project | State | Summary | Similarity |
|---|---|---|---|---|
| #3125 cli: cleanup error handling | snapcraft | merged | Merged CLI error handling cleanup. Removed legacy try/except block for Ubuntu 16.04 and switched to inline type hints to eliminate noqa comments. Approved by reviewer and passed CI checks. | |
| #1790 cli: include consistent commands to fix error conditions | snapcraft | merged | Merged implementation of consistent CLI commands to resolve error conditions. Closes #1733, depends on #1640, and received reviewer approval with minimal code changes across three files. | |
| #1347 cli: do not duplicate errors | snapcraft | merged | Merged a fix preventing duplicate CLI error output caused by removing sys.exit in load_config. The PR refactors error handling to prevent recurrence, received approval, and successfully resolves the issue. | |
| #1429 cli: properly handle exceptions in lifecycle | snapcraft | closed | Superseded by PR #1436. The changes improved lifecycle CLI exception handling, displaying user-friendly messages for SnapcraftError and tracebacks for other exceptions based on debug mode. | |
| #1495 cli: don't raise from excepthook | snapcraft | merged | Merged a fix to prevent raising exceptions in the CLI excepthook, which caused confusing Python error messages. The change manually prints tracebacks and exits cleanly. Approved by two reviewers and passed CI. |