fix(host-service): keep repo resolution errors out of the getDiff 500 wrapper

Closed
SU
17d ago
+1-1

Problem

pullRequests.getDiff reported an INTERNAL_SERVER_ERROR to Sentry when the project's local repo path could not be inspected as a git repository (e.g. the folder was moved or deleted). That is a user-environment state, not a bug. The Sentry title also carried the user's absolute local path.

Root cause

resolveGithubRepo already classifies its failures at the throw site: PRECONDITION_FAILED (project not set up) and BAD_REQUEST (not a git repo / no GitHub remote). getDiff called it inside a try/catch meant for the GitHub diff fetch, and rewrapped every error as INTERNAL_SERVER_ERROR. That reclassification sends it through sentryMiddleware. The sibling procedures getContent and getThreads call resolveGithubRepo outside any wrapper and do not have this problem.

Fix

Move the resolveGithubRepo call above the try, so its own classification propagates. The try/catch still wraps fetchPullRequestDiff failures as before. Renderer callers only display the error message, so the code change (500 → 400/412) does not affect released clients; the projectNotSetup error-shape data now also reaches the client, as it does for getContent.

Verification

$ bunx biome check packages/host-service/src/trpc/router/pull-requests/procedures/get-diff.ts
Checked 1 file in 28ms. No fixes applied.

$ cd packages/host-service && bun run typecheck
$ tsc --noEmit --emitDeclarationOnly false
(exit 0)

$ bun test packages/host-service/src/trpc/router/pull-requests
 75 pass
 0 fail
 193 expect() calls
Ran 75 tests across 12 files. [3.15s]

Refs HOST-SERVICE-CF


Summary by cubic

Stops getDiff from wrapping repo resolution failures as INTERNAL_SERVER_ERROR, so a user-environment state (moved or deleted git repo) no longer shows up in Sentry as a bug with the user's absolute path in the title.

resolveGithubRepo already throws a PRECONDITION_FAILED (project not set up) or BAD_REQUEST (not a git repo / no GitHub remote) error. The call now sits outside the try/catch, like it already does in getContent and getThreads, so those classifications propagate as-is. The try still wraps fetchPullRequestDiff failures exactly as before. Renderer callers only display the error message, so the 500 → 400/412 change doesn't affect released clients; the projectNotSetup error-shape data now also reaches the client as it does for getContent.

Summary by CodeRabbit

  • Bug Fixes
    • Errors encountered while locating a repository now retain their original response instead of being converted to a generic server error. Errors encountered while fetching a pull request’s diff continue to use the existing error handling.