← Back to PRs

#4036: fix: include cause detail in agent connection error diagnostic

by anajuliabit open 2026-01-29 15:20 View on GitHub →
gateway
## Summary - Add `describeNetworkError()` helper to `src/infra/errors.ts` that extracts one level of `.cause` from network errors (e.g. Anthropic SDK's `APIConnectionError`) and appends the underlying code or message - Use it in the agent catch block (`src/gateway/server-methods/agent.ts`) so users see e.g. `Connection error. (UNABLE_TO_VERIFY_LEAF_SIGNATURE)` instead of just `Connection error.` - Add tests for the new function and existing error utilities in `src/infra/errors.test.ts` ## Test plan - [x] `pnpm build` — type-check passes - [x] `pnpm test src/infra/errors` — 16 tests pass - [x] `pnpm lint` — clean 🤖 Generated with [Claude Code](https://claude.com/claude-code) <!-- greptile_comment --> <h2>Greptile Overview</h2> <h3>Greptile Summary</h3> This PR adds a new `describeNetworkError()` helper (`src/infra/errors.ts`) that formats network-related errors by extracting a single level of `err.cause` and appending either the underlying `code` or `message`. The agent request handler (`src/gateway/server-methods/agent.ts`) now uses that helper when returning `UNAVAILABLE` errors so clients see more diagnostic detail. A new `src/infra/errors.test.ts` file provides unit coverage for `extractErrorCode`, `formatErrorMessage`, `formatUncaughtError`, and the new `describeNetworkError`. <h3>Confidence Score: 4/5</h3> - This PR is generally safe to merge and improves error diagnostics with minimal behavioral change. - Changes are localized (new helper + wiring in one catch block) and are covered by focused unit tests. The main remaining concern is edge cases where thrown values or causes are non-Error objects, which may lead to low-signal summaries (e.g., JSON stringification like "{}"). - src/infra/errors.ts (edge-case formatting for non-Error throws/causes) <!-- greptile_other_comments_section --> <sub>(2/5) Greptile learns from your feedback when you react with thumbs up/down!</sub> <!-- /greptile_comment -->

Most Similar PRs