fix(thread/github): degrade a non-JSON sandbox-git response instead of raw SyntaxError - #6358
Open
pedrofrxncx wants to merge 1 commit into
Open
fix(thread/github): degrade a non-JSON sandbox-git response instead of raw SyntaxError#6358pedrofrxncx wants to merge 1 commit into
pedrofrxncx wants to merge 1 commit into
Conversation
…f raw SyntaxError
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.
Source: bug found while auditing the GitHub tooling layer (
apps/web/src/components/thread/github/). This is the same failure-mode this repo has already fixed at several other HTTP boundaries (seeapps/api/src/tools/github/graphql.ts'sparseGraphqlBody, and the merged "degrade a malformed 2xx body instead of raw SyntaxError" lane, e.g. #6289/#6293/#6161) —sandbox-git-api.ts's sharedparseJsonhelper never got the same treatment.Payoff: every Fast Preview git call (
/git/status,/git/diff,/git/publish,/git/rebase,/git/discard,/git/suggest-commit,/git/judge-review) goes throughsandboxFetch+parseJson. A gateway/proxy hiccup between the browser and the sandbox daemon (a 502/504 HTML error page, or an empty body on a dropped connection) is not guaranteed to be JSON even when it's a real response, andres.json()throws a raw, unhandledSyntaxErrorin that case ("Unexpected token '<'") instead of the typedSandboxGitErrorevery caller in this file branches on — includingisSandboxUnreachable, which backs off polling instead of hammering a downed sandbox. A raw SyntaxError bypasses that backoff and surfaces as an opaque toast.Fix:
parseJsonnow reads the body as text and tolerates a JSON-parse failure on both the success and failure path, always throwingSandboxGitError(carrying the real HTTP status) instead of lettingJSON.parse's exception escape uncaught. Behavior for a well-formed JSON response (ok or error-shaped) is unchanged.Regression test: added to the existing
sandbox-git-api.test.ts(which already covers this file's pure logic) — a non-JSON error page on a non-2xx status, and a non-JSON body on a 2xx status, both now reject withSandboxGitErrorcarrying the response's status instead of an unhandledSyntaxError.To verify:
bun test apps/web/src/components/thread/github/sandbox-git-api.test.tsLocally ran:
bun run fmt,cd apps/web && bunx tsc --noEmit, the targeted test file above (76 pass), andbunx oxlinton both changed files (0 warnings/errors). Full CI validates the rest.Summary by cubic
Degrades non-JSON responses from sandbox git endpoints to a typed
SandboxGitErrorwith HTTP status instead of leaking a rawSyntaxError. This restores backoff and consistent error handling across Fast Preview git operations; behavior for valid JSON is unchanged.parseJsonnow reads the body as text, attempts JSON parse, and throwsSandboxGitError(status)on parse failure or any non-2xx response.SandboxGitErrorandparseJson; adds tests covering non-JSON bodies (2xx and non-2xx) and JSON error shapes.SandboxGitError(e.g.,isSandboxUnreachable) now back off on gateway errors instead of showing opaque toasts.Written for commit 4c8d5fc. Summary will update on new commits.