fix(tools): catch uncaught exceptions in submit_cves (ValueError) and get_github_advisory (ValueError) - #95
Merged
Merged
Conversation
…dvisory
Two real exception-safety bugs, found by previous test suites and evolution log:
Bug 1 — submit_cves (ValueError escapes try/except):
The raise ValueError(...) for a missing CVE_SUBMIT_URL was placed *outside*
the try/except block, so callers received a raw ValueError instead of the
expected {status: "error"} dict. Fix: move URL resolution, validation, and
the raise inside the existing try block so the broad `except Exception`
handler catches it and returns a proper error response.
Bug 2 — get_github_advisory (ValueError missing from except clause):
The final except clause only listed (KeyError, IndexError), omitting
ValueError. response.json() raises ValueError (and its subclass
json.JSONDecodeError) on malformed response bodies — these escaped silently.
Fix: expand clause to except (KeyError, IndexError, ValueError).
Tests (tests/test_bug_fixes.py — 18 new tests, 0 failures):
- submit_cves: missing-URL returns error status, never raises, toolUseId
preserved, error text mentions config key, happy path (URL via env + config)
still calls requests.post and returns success, HTTPError/ConnectionError
still caught
- get_github_advisory: ValueError/JSONDecodeError caught and returned as
error dict, JSONDecodeError subclass caught, IndexError still caught,
HTTP 404 still returns not-found message, happy path unaffected, input
validation still short-circuits
Suite delta: 902 → 920 passing (+18), 0 failures
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
Fixes two real exception-safety bugs found by the previous test suites and flagged in the evolution log. Neither was cosmetic — both caused callers to receive an unexpected exception instead of the documented
{"status": "error"}/ error-dict response.Bug 1 —
submit_cves:ValueErrorfor missing webhook URL escapedtry/exceptFile:
src/manus_agent/tools/submit_cves.pyRoot cause: The
raise ValueError(...)guard for a missingCVE_SUBMIT_URLwas placed outside thetry/exceptblock. Any caller that hadn't configured the webhook received a rawValueErrorinstead of the expected{"status": "error", ...}dict.Fix: Moved URL resolution (
Config.from_file()lookup +os.environ.getfallback +raise) inside thetryblock so the existing broadexcept Exceptionhandler catches it and returns a proper error response — consistent with all other error paths in the function.Before:
After:
Bug 2 —
get_github_advisory:ValueErrormissing fromexceptclauseFile:
src/manus_agent/tools/get_github_advisory.pyRoot cause: The final
except (KeyError, IndexError)clause did not includeValueError.response.json()raisesValueError(and its subclassjson.JSONDecodeError) when the response body is malformed — a real scenario for transient API errors returning HTML error pages. These exceptions escaped silently to the caller.Fix: One-line change — expand to
except (KeyError, IndexError, ValueError).Before:
After:
Tests —
tests/test_bug_fixes.py(18 new, 0 failures)Bug 1 coverage (10 tests):
status == "error", never raises,toolUseIdpreserved, error text mentions config keyCVE_SUBMIT_URLenv var →requests.postcalled, returns successconfig.webhooks.cve_submit_url→ returns successconfig.webhooksisNoneHTTPErrorfromrequests.poststill caught and returnedConnectionErrorstill caught and returnedBug 2 coverage (8 tests):
ValueErrorfromresponse.json()→ returns{"error": ...}dict, never raisesjson.JSONDecodeError(subclass ofValueError) → also caughtIndexErrorstill caught (regression guard){"message": "No advisory found..."}(regression guard)Suite delta: 902 → 920 passing (+18), 0 failures
Open PRs checked — no overlap
Confirmed no duplicate work against all open PRs:
#51, #53, #54, #58, #60, #64, #65, #67, #74, #75, #76, #77, #78, #79, #80, #82, #83, #85, #86, #87, #88, #89, #90, #91, #92, #93, #94
None of those PRs address
submit_cvesexception safety orget_github_advisoryValueError handling.