Repository navigation
Enhance error capture with detailed context and cause chains - #258
Merged
Merged
Conversation
…- record errors that never reached captureServerException Many serious failures never reached the ERRORS table because they were caught and answered as something else, or thrown where nothing records: - the sink itself: causes and AggregateError members were dropped, as were Postgres error fields; array/string contexts, NUL characters and non-uuid uids made the insert fail - the API runtime: errors in a route's preflight / middleware went to Hono's default handler; a failure reported after the request context was released opened a database handle nothing closed - Server Components and other route handlers: no onRequestError hook - operation catch-alls answering 500 without recording - infrastructure failures answered as caller errors: route guard key loading and revocation lookups (user looks signed out), refresh grant keyset lookup (invalid_grant made clients drop good refresh tokens; it is now a recorded 500), userinfo, introspection, JWKS access assertions, authorize app lookup, audience checks, argon2 verification - silently degraded security: rate limits failing open on Redis errors, failed watermark cache invalidation, MFA alert emails (two were sent fire-and-forget after the request's db/redis were released) - pages that redirect to an error page or render defaults on failure Adds reportServerException() (opens its own db handle, optional throttle) for code without a handle, and keeps the original error as `cause` on rethrows along the token-verification and settings paths. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MAzy4APcqDFwdYmCGUqXpu
…q7q1 main already shipped auth-server-sdk 0.32.6/0.32.7, trpc-backend-init 0.9.77/0.9.78 and auth-server 0.55.3-0.55.5, so this branch's bumps move to auth-server-sdk 0.32.8, trpc-backend-init 0.9.79, auth-server 0.55.6. whoami keeps main's client-app refresh-token bearer scheme alongside the error capture import. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MAzy4APcqDFwdYmCGUqXpu
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR significantly improves error reporting and debugging by enhancing the
captureServerExceptionfunction to capture richer error context, including cause chains, aggregated errors, and error-specific properties (like database error codes). It also introducesreportServerExceptionfor code paths without a database handle, and adds comprehensive error handling throughout the codebase.Key Changes
Core Error Capture Infrastructure
buildErrorRow(): New exported function that constructs error rows with:AggregateErrormembers rendered into the stackcode,detail,constraint) captured aserror_detailsin contextuidfield (invalid UUIDs moved to context)reportServerException(): New module for error reporting without a database handle in scope:captureServerException(): Refactored to usebuildErrorRow()for cleaner separation of concernsError Handling Improvements
API error handling (
src/lib/api/app.ts):reportServerExceptionToken verification (JWKS, refresh tokens, userinfo):
Route guards (
RouteGuardJwtKeysManager):Password verification: Captures argon2 verification failures with context
Redis failures: Rate limiter records Redis outages (once per minute per limiter)
Testing
captureServerException.test.ts: Comprehensive tests forbuildErrorRow()covering:app.test.ts: Tests for API error capture in middleware and preflight handlersNext.js Integration
instrumentation.ts: New file withonRequestErrorhook to capture:Version Bumps
@schemavaults/auth-server: 0.55.2 → 0.55.3@schemavaults/auth-server-sdk: 0.32.5 → 0.32.6@schemavaults/trpc-backend-init: 0.9.76 → 0.9.77Notable Implementation Details
Object.entries()with try/catch for throwing getterscaptureServerExceptionmust not be rolled back afterward (ERRORS row would be lost)https://claude.ai/code/session_01MAzy4APcqDFwdYmCGUqXpu