Skip to content

fix(sandbox): return 400 instead of 500 when the diff base branch isn't on origin - #5142

Merged
pedrofrxncx merged 1 commit into
mainfrom
fix/git-diff-base-branch-not-found-status-w2
Jul 23, 2026
Merged

pedrofrxncx merged 1 commit into
mainfrom
fix/git-diff-base-branch-not-found-status-w2

Conversation

@pedrofrxncx

@pedrofrxncx pedrofrxncx commented Jul 23, 2026 •

Copy link
Copy Markdown
Collaborator

Bug found while auditing packages/sandbox/daemon/routes/git.ts: computeDiffAgainstBase() (used by POST /git/diff when a base is supplied) threw a plain Error when the requested base branch doesn't exist on origin (typo, deleted branch). That fell through the handler's generic catch and surfaced as an opaque 500, the same class of bug already fixed elsewhere in this file for InvalidRemoteBranchNameError (400) and PublishBlockedError/RebaseBlockedError (409) — this one case was missed.

A maintainer wants this because a bad/stale base branch is a client input problem, not a server fault; the UI can distinguish and retry/report accordingly instead of treating it as a crash.

Failure scenario: client POSTs /git/diff with a syntactically-valid base (e.g. a deleted or mistyped branch name) that has no matching ref on origin — previously a 500 with a generic error body; now a 400 with the same descriptive message ("Base branch '' not found on origin"). Added a regression test (diff POST returns 400 (not 500) when the base branch isn't on origin) asserting the new status/body.

Reviewer check: bun test packages/sandbox/daemon/routes/git.test.ts (33 pass, includes the new test).

Locally verified: bun run fmt, cd packages/sandbox && bunx tsc --noEmit (clean), and the targeted test file above. Full CI validates the rest.


Summary by cubic

Return 400 (Bad Request) instead of 500 when POST /git/diff is called with a base branch that isn’t on origin. This clarifies client input errors so the UI can handle them.

  • Bug Fixes
    • Added BaseBranchNotFoundError and mapped it to 400 in packages/sandbox/daemon/routes/git.ts.
    • Error message is "Base branch '' not found on origin".
    • Added a regression test in packages/sandbox/daemon/routes/git.test.ts.

Written for commit 97b2091. Summary will update on new commits.

Review in cubic

@pedrofrxncx
pedrofrxncx enabled auto-merge (squash) July 23, 2026 21:46
@pedrofrxncx
pedrofrxncx merged commit 3fdc8d0 into main Jul 23, 2026
15 checks passed
@pedrofrxncx
pedrofrxncx deleted the fix/git-diff-base-branch-not-found-status-w2 branch July 23, 2026 21:51
decocms Bot pushed a commit that referenced this pull request Jul 23, 2026
PR: #5142 fix(sandbox): return 400 instead of 500 when the diff base branch isn't on origin
Bump type: patch

- @decocms/sandbox (packages/sandbox/package.json): 1.22.1 -> 1.22.2
- deploy/helm/sandbox-env (chart 0.9.20) (deploy/helm/sandbox-env/values.yaml deploy/helm/sandbox-env/Chart.yaml): image.tag/appVersion -> 1.22.2

Deploy-Scope: both
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant