fix(spawn): map invalid branch name to 400 instead of opaque 500#213
fix(spawn): map invalid branch name to 400 instead of opaque 500#213codebanditssss wants to merge 1 commit into
Conversation
Greptile SummaryFixes the missing typed sentinel for invalid git branch names so that
Confidence Score: 5/5Safe to merge; the change is a narrow, well-tested addition of a new error sentinel and its mapping — no existing behavior is altered. The diff touches only the error-classification path: a new sentinel, one wrapping site, one switch case, and matching tests. The dual-%w format string is valid on Go 1.20+ (the module declares 1.25), errors.Is traversal is unaffected, and no existing mappings are disturbed. No files require special attention. Important Files Changed
Sequence DiagramsequenceDiagram
participant CLI as ao CLI
participant Svc as session.Service
participant WS as gitworktree.Workspace
participant Git as git check-ref-format
CLI->>Svc: "Spawn(branch="bad branch!!")"
Svc->>WS: Create(WorkspaceConfig)
WS->>Git: check-ref-format --branch "bad branch!!"
Git-->>WS: exit 1 (fatal: not a valid branch name)
WS-->>Svc: fmt.Errorf("%w: %q (%w)", ErrBranchInvalid, branch, gitErr)
Note over Svc: toAPIError detects ErrWorkspaceBranchInvalid
Svc-->>CLI: 400 INVALID_BRANCH (git's reason included)
Reviews (2): Last reviewed commit: "fix(spawn): map invalid branch name to 4..." | Re-trigger Greptile |
validateBranch returned an untyped error for a name rejected by git check-ref-format, so toAPIError fell through to INTERNAL_ERROR 500. Add a ports.ErrWorkspaceBranchInvalid sentinel (mirroring the not-fetched / checked-out-elsewhere ones), wrap it in validateBranch, and map it to INVALID_BRANCH (400). Completes the residual of #152 Bug 3, which typed the not-fetched and checked-out-elsewhere cases but left the invalid-format case collapsing to 500. Closes #212
a84aa76 to
18b7480
Compare
Closes #212.
Problem
ao spawn --branch "<invalid name>"returned an opaqueINTERNAL_ERROR500.gitworktree.validateBranchwrapped thegit check-ref-formatfailure in an untyped error, sotoAPIErrorfell through todefaultand the envelope collapsed it to 500.This is the residual of #152 Bug 3: that RCA typed the not-fetched and checked-out-elsewhere branch errors (now 400/409), but the invalid-format case — the first check in
validateBranch— never got a sentinel.Change
ports.ErrWorkspaceBranchInvalid, aliased in the gitworktree adapter alongside the existing two.validateBranch(keeps git's own message for the user).toAPIError→apierr.Invalid("INVALID_BRANCH", ...)(400).Test
TestCreateRejectsInvalidBranchName(gitworktree):Createwith a bad branch returnsErrWorkspaceBranchInvalidand stops before any further git call.TestToAPIErrorMapsWorkspaceBranchSentinels: adds theINVALID_BRANCHmapping case.go build ./...and fullgo test ./...pass.--branch "bad branch name!!"now returnsINVALID_BRANCH(exit 1) with git's reason, instead ofInternal server error.