1.1 KiB
1.1 KiB
8. Avoid Catching BaseException in CLI Dispatch
Summary
Change CLI dispatch error handling so process-control exceptions such as KeyboardInterrupt and SystemExit are not swallowed.
Implementation Steps
- Change
execute_commandto catchExceptioninstead ofBaseException. - Keep mapped, expected errors handled through the existing command error mapping or its replacement.
- Print handled user-facing errors to
stderrinstead ofstdout. - Allow unmapped exceptions,
KeyboardInterrupt, andSystemExitto propagate normally. - Consider adding debug logging for unexpected exceptions after the logging plan exists.
Public Interface Changes
- Expected command errors still return a non-zero exit code.
- Handled error messages move from stdout to stderr.
- Interrupt and process-exit behavior becomes conventional.
Test Plan
- Test that a mapped exception returns
1and writes to stderr. - Test that
KeyboardInterruptis not caught byexecute_command. - Test that unmapped exceptions still propagate.
Assumptions
- Returning
1for handled user errors remains acceptable until the exit-code conventions plan is implemented.