fix(interface): exit cleanly on unhandled LLM BadRequestError (#510)#590
fix(interface): exit cleanly on unhandled LLM BadRequestError (#510)#590Rome-1 wants to merge 1 commit into
Conversation
…ix#510) When run_cli/run_tui raise an unhandled exception (e.g. openai.BadRequestError from a provider 400), main() re-raised it, surfacing a raw traceback and a PyInstaller crash dump in the binary release after the CLI/TUI had already rendered a user-friendly error panel. Exit with status 1 instead so the finally-block cleanup still runs while suppressing the noisy traceback. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Greptile SummaryThis PR fixes a UX regression where unhandled LLM provider errors (e.g.,
Confidence Score: 4/5Safe to merge for the intended use case; the The fix correctly resolves the traceback/crash-dump problem and the The Important Files Changed
|
Fixes #510
When an unhandled provider error (e.g.
openai.BadRequestError/ HTTP 400) reaches the top-levelmain()handler, the bareraisere-surfaces a raw Python traceback — and in the PyInstaller binary release, a "Failed to execute script" crash dump — even though the CLI/TUI layer has already rendered a user-friendly error panel. This replaces theraisewithsys.exit(1), so the process still exits non-zero but without the confusing traceback. Thefinallyblock (report cleanup with statusfailed, posthog/scarfend) still runs, and the success-path display code after thetry/finallycorrectly stays unreached.Testing
pytest tests/test_main_exit.py— 1 passed. The test mocks arg parsing, Docker, env validation, telemetry, andasyncio.run, makes the scan run raiseopenai.BadRequestError, and assertsmain()raisesSystemExitwith code 1 rather than propagating the provider error. Confirmed it fails on currentmain(theBadRequestErrorpropagates) and passes with this change.ruff checkandruff format --checkclean on the diff; pyupgrade (UP) rules clean via ruff;bandit -c pyproject.tomlclean.mypyhook errors out internally on the bundledopenaiSDK onmainas well, so mypy is not asserted here.