fix: raise GitHubDocsError for a read timeout or a non-JSON 2xx body - #13
Merged
dmccoystephenson merged 2 commits intoSep 27, 2026
Merged
Conversation
_request caught HTTPError and URLError only, so a timeout raised by resp.read() and a JSONDecodeError on a 2xx body escaped as themselves, breaking the README's promise that everything which stops an edit landing is a GitHubDocsError. Both are now converted, through _redact, with the body never quoted back. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
json.loads on bytes that are not UTF-8 raises UnicodeDecodeError, which is not a JSONDecodeError, so it still escaped. Catch ValueError, which covers both. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
Author
|
Self-review rubric (head
Findings:
This review comment was drafted during a Gardener session (https://github.com/Stephenson-Software/gardener). drafted by Claude on behalf of Daniel Stephenson |
2 of 3 tasks
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
GitHubDocsClient._requestnow converts a 2xx body that fails to decode intoGitHubDocsErrorcarrying the response status. The catch isValueError, which covers bothjson.JSONDecodeErrorand theUnicodeDecodeErrorraised for bytes that are not UTF-8. The body is not quoted back, matching how the error path already handles a non-JSON body.OSErrorescaping the request (asocket.timeoutraised byresp.read(), or a connection reset mid-read;urlopenwraps neither inURLError) is now converted intoGitHubDocsError("could not reach GitHub: …")with no.status.OSErrorwas chosen oversocket.timeoutalone because a reset during the read breaks the README's contract in exactly the same way.self._redact(...).TestErrorSurfacecases were added, one per path.python/README.md's Errors section ("Everything that stopped an edit from landing raisesGitHubDocsError") already stated the intended contract and is now accurate; it is unchanged. One remaining path, a timeout inside theHTTPErrorhandler's owne.read(), is tracked separately in #14.Half touched:
python/only.Test plan
Ran 49 tests … OK(run under local Python 3.8 via asys.pathrunner, since env-var prefixes were unavailable in the sandbox; CI's 3.9–3.13 matrix is the real anchor).jsandpythonleg.Merge note
This diff touches error-message construction in
python/src/github_docs/client.py, which is on the loop's do-not-auto-merge list (the token-redaction path is a security control). It is therefore left for human review rather than merged autonomously.Deferred issues
Closes #11
This PR description was drafted during a Gardener session (https://github.com/Stephenson-Software/gardener).
🤖 Generated with Claude Code
drafted by Claude on behalf of Daniel Stephenson