fix(desktop): classify detached-HEAD main-repo open as typed BAD_REQUEST
Problem
Opening a project's main repository as a workspace (workspaces.openMainRepoWorkspace) throws a plain Error("Could not determine current branch") when the repo has no current branch. The tRPC sentryMiddleware reports this as an INTERNAL_SERVER_ERROR, so an expected user-repo state shows up in Sentry as a 500 (DESKTOP-JM, 3 events on 1.15.1).
Root cause
When the main repo is on a detached HEAD (or an unborn branch), getCurrentBranch returns nothing and the guard at the top of openMainRepoWorkspace throws an untyped Error. Per the classification contract (#6164), expected domain states must be translated into non-500 TRPCErrors at the throw site — this one never was.
Fix
Replace the plain throw with a typed TRPCError:
code: "BAD_REQUEST"— matching the existing detached-HEAD classification ingetLocalBranchOrThrow(routers/changes/git-operations.ts), whose message style this also follows.cause: { kind: "DETACHED_HEAD" }— a plain-object, kind-discriminated cause that the existingerrorFormatterinsrc/lib/trpc/index.tsalready forwards to the renderer.- User-actionable message: "Cannot open this repository from detached HEAD. Please checkout a branch and try again."
No filter, no middleware change — genuine unexpected failures on this path still reach Sentry as before.
Verification
bunx biome check apps/desktop/src/lib/trpc/routers/workspaces/procedures/create.tsChecked 1 file in 19ms. No fixes applied.cd apps/desktop && bun run typecheck$ tsr generate $ tsc --noEmit exit=0- No existing tests cover the changed guard (the adjacent
external-worktree-import.test.tstestsutils/gitonly), so no test run applies.
Refs DESKTOP-JM
https://claude.ai/code/session_2bf90175-44a5-44e3-be07-aeed3182571a
Summary by cubic
Treat opening the main repo on a detached HEAD as a BAD_REQUEST instead of a 500, with a clear action message. Aligns with DESKTOP-JM and keeps this expected state out of Sentry server errors.
Summary by CodeRabbit
- Bug Fixes
- Improved error handling when opening a workspace from a detached Git HEAD.
- Displays a clear, user-facing message instead of a generic error.