Repository navigation
feat: add one error envelope and code registry - #102
Merged
Merged
Conversation
|
Sorry @keyurgolani, you've used your own review budget of 250,000 diff characters for the last 7 days. You can request another review in 6 days and 20 hours by commenting |
Reviewer's GuideThis PR establishes the error-envelope foundation without migrating existing routes: a typed registry-driven envelope and outcome API, a file- and status-aware legacy compatibility map, source-scan enforcement for all current codes and codeless bodies, and an architecture decision defining denial semantics for follow-up migrations. Sequence diagram for registry-driven error responsessequenceDiagram
participant Route
participant ErrorEnvelope
participant Registry
participant Client
Route->>ErrorEnvelope: errorResponse(code)
ErrorEnvelope->>Registry: read ERROR_CODES[code]
Registry-->>ErrorEnvelope: status and default message
ErrorEnvelope->>ErrorEnvelope: generate timestamp and correlationId
ErrorEnvelope-->>Client: HTTP response with error envelope and registry status
Sequence diagram for legacy error-code compatibilitysequenceDiagram
participant LegacyRoute
participant LegacyMap
participant Registry
participant Client
LegacyRoute->>LegacyMap: mapLegacyCode(code, status, file)
LegacyMap-->>LegacyRoute: registry code
LegacyRoute->>Registry: errorResponse(registryCode)
Registry-->>LegacyRoute: registered status and message
LegacyRoute-->>Client: standardized error envelope
Flow diagram for concealment and outcome semanticsflowchart TD
Input[Caller supplies code and options] --> Kind{Registry code kind}
Kind -->|Error code| Error[Build success false envelope]
Kind -->|Outcome code| Outcome[Build success true body with top-level code]
Error --> Conceal{NOT_FOUND or CAPABILITY_INVALID}
Conceal -->|Yes| DefaultCopy[Use registry copy and omit details]
Conceal -->|No| CallerCopy[Allow caller message and details]
DefaultCopy --> Response[Return with registry status]
CallerCopy --> Response
Outcome --> OutcomeResponse[Return with registry status]
File-Level Changes
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
error-envelope.ts builds { success: false, error: { code, message,
details?, timestamp, correlationId } } and sends it with the code's one
status from error-codes.ts. Server actions return the same object
without a status, and outcome codes return the success body with a
top-level code. NOT_FOUND and CAPABILITY_INVALID bodies never vary.
The legacy map keys every code that predates the registry by (legacy
code, status, returning file), so each use of TEMPLATE_003 or AUTH_001
maps to one code.
Refs #30
error-codes.test.ts scans src/ with the TypeScript checker. Every *ErrorCodes member and literal error code must be registered or in the legacy map, every response that pairs a fixed code with a fixed status must be mapped, and codeless error bodies under src/app must match the merge-time list #91 owns, which only shrinks. Refs #30
Each service types its error code as its *ErrorCodes union, so the scan resolves a forwarded result.error.code, and it reads the route's status function, default arms, braced clauses and fall-through included. Every legacy row is keyed by (code, status, file, method), with a reason where one method sends one code for two meanings, and must match a response the scan finds. Not-visible rows map to NOT_FOUND. The registry reserves the codes the public issues of 00.1, 00.2, 00.4 and 18.2 define. SIGNUP_DISABLED stays a live code. Refs #30
…tion IDs NOT_FOUND and CAPABILITY_INVALID take no headers, in the types and at runtime, so only timestamp and correlationId vary. A supplied correlationId that isn't 1 to 128 safe characters is replaced with a generated one. Refs #30
The lint job compares src/lib/api/codeless-error-bodies.ts with its copy at the merge base and fails a raised count or an added file. Refs #30
keyurgolani
force-pushed
the
feat/01.2-envelope
branch
from
October 20, 2026 14:03
3bb2b79 to
71f268e
Compare
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.
Implements CHECKMATE-01.2 · envelope
Refs #30
What changed
src/lib/api/error-envelope.tsbuilds{ success: false, error: { code, message, details?, timestamp, correlationId } }.errorResponsesends it with the code's registry status, and server actions returnerrorEnvelope, the same object without a status.correlationIdis generated until 02.1 sessions ([CHECKMATE-02.1] Introduce server-mediated session and assurance policies #32) passes one, and a malformed one is replaced.NOT_FOUNDandCAPABILITY_INVALIDtake no message, details or headers, in the types and at runtime, so aNOT_FOUNDfor a hidden target matches one for a missing target apart fromtimestampandcorrelationId. Outcome codes return the success body with a top-levelcode.src/lib/api/error-codes.tshas the registry, one HTTP status and default copy per code, and the legacy map keyed by (legacy code, status, returning file, HTTP method). The map has 379 rows for all 119 codes onnext: 108*ErrorCodesmembers and 11 literal codes,RUN_SYNC_REMOVEDincluded. Where one method sends one code for two meanings, each row names a reason.codeas its*ErrorCodesunion, so the scan sees which codes a route forwards. Apart from types,TemplateErrorCodesgainsDUPLICATE_FAILEDfor the literal codeduplicate()returned, and threeno-explicit-anyerrors initem.tsandllm.tsare fixed.error-codes.test.tsscanssrc/with the TypeScript checker. The scan is insrc/test/error-code-scan.ts, with fixture tests for status switches, the JSON helpers,withAuthand forwarded codes.codeless-error-bodies.tslists the merge-time 68 codeless error bodies in 12 files, and 21.3 async states ([CHECKMATE-21.3] Standardize truthful async, stale, degraded, conflict, and recovery states #91) owns it. The test fails when a file's count changes.scripts/ci/check-shrinking-lists.mjsruns in the lint job and fails a change that raises a count or adds a file, compared with the merge base.docs/architecture/decisions/denial-semantics.mdrecords the decision.No route moves onto the envelope. 21.3 async states does that.
Why
Denials come back in six shapes, and a code doesn't say what happened.
withAuthsendsTEMPLATE_003with 401, andAUTH_001means both a wrong password and no session. 02.1 sessions, 03.1 memberships (#35), 11.1 commands (#59) and 21.3 async states build on one envelope with one status per code.Verification
Against
origin/nextat 1ff2762, the merge of 01.1 contracts (#101):scripts/ci/lint-changed.mjs): 0 errors, noeslint-disable. The 13 warnings are onesnextalready has in those files.npm run lint: 38 errors, 48 warnings.origin/nexthas 41 and 48, and the three fewer are theno-explicit-anyfixes.npx tsc --noEmit: 0 errors, same asorigin/next.npm teston the fixture: 665 tests in 38 files pass, none skipped, 43 of them new.npm run buildwith PocketBase athttp://127.0.0.1:9: passes.aggregatepasses with all seven jobs run.Each of these fails a test: deleting the
CIRCULAR_REFERENCEcase from the items route's status switch, soITEM_011falls to 500; sending the visibility route's forwarded codes at 418; sendingAUTH_004at 403 throughjsonResponseWithLogout; registering a code at 999; a map row for a response its file doesn't send; sending a reserved code; a live registry code nothing sends or maps to; raising a codeless count; and turning offNOT_FOUNDconcealment. Outside routes and the proxy, the scan skips a send whose code or status it can't pin down.Decisions and owner steps
nexttoday, and the test fails on a code that's neither registered nor mapped. The registry also reserves the codes the public issues of 00.1 storage rules ([CHECKMATE-00.1] Replace permissive PocketBase rules with a default-deny authority matrix #25), 00.2 secret store ([CHECKMATE-00.2] Move provider credentials into encrypted server-custodied secret references #26), 00.4 logger ([CHECKMATE-00.4] Rotate defaults and add emergency security regression gates #28) and 18.2 ledger ([CHECKMATE-18.2] Introduce ordered schema migrations and rebuildable projections #81) define, at the statuses those issues give. Sending a reserved code fails the test until its leaf drops the reservation.NOT_FOUND, per the denial semantics.AUTH_001stays the wrong-password code because 02.1 sessions keeps it, and maps toAUTH_REQUIREDin thellmandrelayroutes.IMPORT_009maps toUNSUPPORTED_VERSION, as 16.1 schemas ([CHECKMATE-16.1] Publish canonical versioned package, workflow, and proof schemas #74) says. Its copy is generic, since 08.2 schedules ([CHECKMATE-08.2] Add timezone-safe schedules, recurrence, due policy, and escalation #51) also returns it for unknown rule semantics.ITEM_011maps to 07.1 run creation's ([CHECKMATE-07.1] Implement idempotent transactional run creation #47)REFERENCE_CYCLE(422), since the step editor branches on it.LLM_007andWEB_005map toRATE_LIMITED. The record widens it to an upstream provider's limit, withdetails.sourcesaying which.UNCHANGED(200) andPOLICY_UNAVAILABLE(503) are reserved for 11.1 commands, andUNCHANGEDgives the outcome path a real code to test. 02.1 sessions registersSESSION_EXPIRED,SESSION_REVOKED,SESSION_LEGACY,REAUTH_REQUIREDandCSRF_REJECTED, and the test pins their statuses for when it does.No owner steps.