AP-129: Typed RepositoryError replaces stringly-typed Error.message across the spine#177
Conversation
…129) Introduce RepositoryError with a discriminated kind union and a single repositoryErrorToAppError mapping in packages/db. Convert all domain throw sites in the db package, fold access-link inactive/lockdown errors into the typed scheme, and route HTTP surfaces through that mapper via worker-runtime unknownErrorToCode, API/upload onError handlers, runIdempotent, and executeRepositoryRoute. Remove duplicate mapRepositoryError copies and inline error.message checks from api and upload routes.
AP-129 Typed RepositoryError replaces stringly-typed Error.message across the spine
Parent: AP-126. Architecture review finding #1. HOT SEAM (db core) — run alone, no other db-touching slice concurrently. Do this first; the contract.errors slice builds on the typed mapping. OutcomeThe Context docs
Problem~32 distinct codes thrown as Likely files / packages
In scope
Out of scope
Acceptance criteria
Required checks
Security / data / operational invariants
Dependencies / blockersNone. Must run alone on the db hot seam. Blocks the contract.errors slice. |
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
|
agent-paste PR preview is ready. API: https://agent-paste-api-pr-177.isaac-a46.workers.dev |
Replace Partial<Record<…>> with Record<RepositoryErrorCode, ErrorCode | null> so every kind requires an explicit mapping entry at compile time. Map infrastructure failures to null (intentional internal_error) instead of omitting them. Add tests covering all kinds and fix worker-runtime dep order.
|
agent-paste PR preview is ready. API: https://agent-paste-api-pr-177.isaac-a46.workers.dev |
|
agent-paste PR preview resources were cleaned up. The shared Preview GitHub Environment is retained for future preview deploys. |
Summary
Domain failures in
packages/dbnow throw a typedRepositoryErrorwith a discriminatedkind, and HTTP workers map them through a singlerepositoryErrorToAppErrorfunction instead of duplicated string switches and inlineerror.messagechecks.Changes
packages/db: AddedRepositoryError,RepositoryErrorCode, andrepositoryErrorToAppError; converted workflow, validation, policy, access-link, and repository throw sites; foldedAccessLinkInactiveError/AccessLinkLockdownErrorinto typed kinds that map to genericnot_foundat the HTTP boundary (ADR 0036).packages/worker-runtime:unknownErrorToCodedelegates torepositoryErrorToAppErrorfirst so registrar-mounted routes get mapping for free.apps/api/apps/upload: Removed bothmapRepositoryErrorcopies and route-levelerror.message === "..."checks; addedexecuteRepositoryRoute/ extendedrunIdempotentand globalonErrorhandlers to use the central mapper.repository-error.test.tsandworker-runtimemapping tests; updated route/db tests to throwRepositoryErrorwhere they mock repository failures.Verification
pnpm verifypnpm test:coveragepnpm openapi:check(unchanged)Notes
current_api_key_not_found→not_authenticated; member web revoke usesnot_found(preserves prior HTTP behavior).lockdown_insert_conflict) still fall through tointernal_error.Linear Issue: AP-129