|
| 1 | +# AGENTS.md — packages/errors |
| 2 | + |
| 3 | +Execution contract for Nebutra's shared error semantics package. |
| 4 | + |
| 5 | +## Scope |
| 6 | + |
| 7 | +Applies to everything under `packages/platform/errors/`. |
| 8 | + |
| 9 | +This package owns canonical application error codes, typed error classes, |
| 10 | +API-safe serialization helpers, and the framework-agnostic error middleware |
| 11 | +shape. It is the shared error vocabulary layer, not the place for service-local |
| 12 | +logging policy or provider-specific exception translation. |
| 13 | + |
| 14 | +## Source Of Truth |
| 15 | + |
| 16 | +- Public package surface: `package.json`, `src/index.ts` |
| 17 | +- Canonical error code catalog: `ERROR_CODES` |
| 18 | +- Base error class and serialization behavior: `AppError`, `AppErrorOptions`, |
| 19 | + `AppError.toJSON()` |
| 20 | +- Specific error subclasses and their default status semantics: |
| 21 | + `ValidationError`, `UnauthorizedError`, `ForbiddenError`, `NotFoundError`, |
| 22 | + `ConflictError`, `RateLimitError`, `QuotaExceededError`, |
| 23 | + `ExternalServiceError`, `DatabaseError` |
| 24 | +- API response and status helpers: `toApiError`, `getStatusCode` |
| 25 | +- Framework boundary for request-safe error responses: `errorHandler` |
| 26 | +- Assertion and wrapper helpers: `tryCatch`, `assert`, `assertFound` |
| 27 | + |
| 28 | +Treat `README.md` as descriptive only. If docs drift, update `src/index.ts` |
| 29 | +instead of preserving outdated examples. |
| 30 | + |
| 31 | +## Contract Boundaries |
| 32 | + |
| 33 | +- Keep `ERROR_CODES` as the canonical shared vocabulary. Additive changes are |
| 34 | + safest; renames or removals are compatibility changes for callers, handlers, |
| 35 | + and logs. |
| 36 | +- Treat `AppError` and `ApiErrorResponse` as the stable serialization boundary. |
| 37 | + Do not leak raw unknown errors or provider-specific details through |
| 38 | + `toApiError`. |
| 39 | +- Preserve default status-code mapping in `getDefaultStatusCode()` unless the |
| 40 | + compatibility change is deliberate and coordinated with consumers. |
| 41 | +- Keep `errorHandler()` framework-agnostic and request-safe. Its job is to map |
| 42 | + errors into structured JSON and invoke the optional `onError` callback, not |
| 43 | + to own logging destinations or transport-specific side effects. |
| 44 | +- Preserve the distinction between operational and non-operational errors. |
| 45 | + `DatabaseError` and other server faults should not be quietly normalized into |
| 46 | + benign client semantics. |
| 47 | +- Keep assertion helpers thin wrappers over the shared error types. Do not |
| 48 | + embed app-specific policy or database lookups here. |
| 49 | + |
| 50 | +## Generated And Derived Files |
| 51 | + |
| 52 | +- This package currently exports source directly and has no checked-in |
| 53 | + generated source of truth. |
| 54 | +- Do not hand-edit future build output, coverage artifacts, or transient |
| 55 | + TypeScript output. |
| 56 | +- If packaging changes later, update the source files above rather than derived |
| 57 | + artifacts. |
| 58 | + |
| 59 | +## Validation |
| 60 | + |
| 61 | +- Error type, code, or middleware changes: |
| 62 | + `pnpm --filter @nebutra/errors exec tsc --noEmit` |
| 63 | +- Because this package currently has no package-local tests, verify the |
| 64 | + narrowest downstream consumer that exercises the changed error contract when |
| 65 | + behavior changes are non-trivial. |
0 commit comments