fix(api_server): replace bare except: with specific exception types#90
Merged
warren618 merged 1 commit intoMay 10, 2026
Merged
Conversation
Three bare except: clauses in api_server.py silently caught BaseException
(KeyboardInterrupt, SystemExit, GeneratorExit) in addition to ordinary
errors. That makes the API server unresponsive to Ctrl+C inside these
blocks and hides real bugs (NameError, AttributeError) as silent passes.
The blocks themselves are best-effort metadata extraction from per-run
artifact files, where falling through with the default values is the
right behavior — but only for the specific I/O / parse failures these
blocks can actually produce. The new clauses spell those out:
- lines 1015, 1022 (req.json / planner_output.json prompt extraction):
except (json.JSONDecodeError, OSError)
- line 1042 (metrics.csv numeric parse):
except (OSError, ValueError)
Behavior is unchanged for the failures the blocks are designed to swallow;
KeyboardInterrupt, SystemExit, and programming errors now propagate as
they should.
Collaborator
|
Thanks for the cleanup. The narrowed exception handling keeps the intended best-effort behavior while avoiding bare |
This was referenced May 10, 2026
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
except:clauses inagent/api_server.pywith explicit exception classes.KeyboardInterrupt/SystemExit/ programming bugs now propagate as they should.Why
Three blocks in
api_server.pyuse bareexcept:— which catchesBaseExceptionsubclasses includingKeyboardInterrupt,SystemExit, andGeneratorExit. That makes the API server unresponsive to Ctrl+C inside these blocks and silently hides real bugs (NameError,AttributeError) as no-op passes.The blocks themselves are best-effort metadata extraction from per-run artifact files where falling through with the default value is the right behaviour — but only for the specific I/O / parse failures these blocks can actually produce. Tightening the catch surface preserves that intent while removing the foot-gun.
Changes
req.jsonprompt extractionexcept:except (json.JSONDecodeError, OSError):planner_output.jsonprompt extractionexcept:except (json.JSONDecodeError, OSError):metrics.csvnumeric parseexcept:except (OSError, ValueError):The other
except Exception:clauses in this file (e.g. lines 638, 730, 745) already excludeBaseExceptionand are out of scope for this PR.Test plan
pytest --ignore=agent/tests/e2e_backtest --tb=line -qpasses —test_settings_api,test_security_auth_api, andtest_upload_apiall still green.grep -nE '^\s+except:\s*$' agent/api_server.pyreturns no matches.Checklist
CONTRIBUTING.md(Conventional Commit prefixfix:, no comment-preserved code).