fix(server): keep /api/diff selection state intact when diff parsing fails#440
Open
kiakiraki wants to merge 1 commit into
Open
fix(server): keep /api/diff selection state intact when diff parsing fails#440kiakiraki wants to merge 1 commit into
kiakiraki wants to merge 1 commit into
Conversation
…fails A single request with an invalid ref (e.g. /api/diff?target=deleted-branch) permanently broke the server: currentSelection was overwritten before parseDiff succeeded, so every subsequent parameter-less request reused the bad ref and returned 500 until restart. The handler also had no try/catch, so failures surfaced as Express's default HTML stack trace. Move the currentSelection update after the diff is successfully resolved and return a JSON 500 error on parse failure, matching the error handling pattern of the other API endpoints. Add a regression test covering the JSON 500 response and the recovery of subsequent requests, replacing the previously skipped placeholder test. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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
currentSelectionupdate in the/api/diffhandler to after the diff is successfully resolved, so a request with an invalid ref no longer poisons the server state used as the fallback for subsequent requestshandles invalid commit gracefullyplaceholderRoot cause
In the
/api/diffhandler,currentSelection = requestedSelection;ran beforeparser.parseDiff(). When a request contained an invalid ref (e.g./api/diff?target=deleted-branch— a branch deleted while switching revisions, or a hand-edited URL), the parse failed but the invalid selection had already overwrittencurrentSelection. Every subsequent parameter-less request (such as the initial fetch on page reload) then fell back to the poisoned selection and kept returning 500 until the server was restarted. The handler also had no try/catch, so the failure surfaced as Express's default HTML error page instead of JSON.Reproduction (before this fix)
Verification
pnpm check/pnpm format/pnpm knip/pnpm test/pnpm buildall pass🤖 Generated with Claude Code