fix(osv-check): guard json.loads against non-JSON API responses - #29696
Open
annguyenNous wants to merge 1 commit into
Open
annguyenNous wants to merge 1 commit into
annguyenNous wants to merge 1 commit into
Conversation
The OSV API may return non-JSON responses (502 HTML, rate-limit pages) which cause json.JSONDecodeError in _query_osv(). While the caller already catches Exception (fail-open), handling this inside the function provides a clearer error message and returns the expected empty list type. Fix: wrap json.loads(resp.read()) in try/except json.JSONDecodeError, log at debug level, and return an empty list.
|
Subset of #29019 which already guards this exact json.loads() call in tools/osv_check.py along with several other unguarded sites (weixin, CDP, api_server) and adds atomic writes. |
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.
Problem
_query_osv()intools/osv_check.pycallsjson.loads(resp.read())without atry/exceptguard. When the OSV API returns a non-JSON response (HTTP 502 HTML page, rate-limit response, or gateway error), this raisesjson.JSONDecodeError.While the caller already catches
Exception(fail-open pattern), handling this inside_query_osv()provides:listtype instead of raisingFix
Wrap
json.loads(resp.read())intry/except json.JSONDecodeError, log at debug level, and return an empty list.Diff: +5 lines, -1 line (1 file)
Testing
ast.parse()passes