Skip to content

feat(errors): expose producer classification - #1830

Open
Zetazzz wants to merge 2 commits into
mainfrom
preserve-error-causes-and-classification-p-d336aa53
Open

Zetazzz wants to merge 2 commits into
mainfrom
preserve-error-causes-and-classification-p-d336aa53

Conversation

@Zetazzz

@Zetazzz Zetazzz commented Sep 15, 2026

Copy link
Copy Markdown
Contributor

parse() returned a classification without indicating whether the producer supplied it or the registry supplied the default. Adapters such as constructive-db storage therefore had to inspect DETAIL/GraphQL fields again to retain their own default for undeclared classifications.

This adds optional ParsedError.explicitClass metadata from the valid producer classification the parser actually used. It covers canonical errors, PostgreSQL DETAIL and GraphQL extensions while preserving the existing precedence, registry defaults, HTTP hints, messages and wrapping behavior. The README explains that the metadata describes the immediate input and shows how adapters can use it.

Validation:

  • All 5 errors test suites passed: 56 tests, including 7 producer-classification tests.
  • CJS/ESM builds, declaration generation and publish-layout checks passed.
  • Scoped ESLint, built-package smoke checks and git diff --check passed.

Supports the classification-parser cleanup in constructive-db #3656 once this API is released.

@tenki-reviewer

tenki-reviewer Bot commented Sep 15, 2026

Copy link
Copy Markdown

Review complete. No issues found — approved ✅.


This PR enhances the packages/errors package by threading optional cause through the ConstructiveError constructor, the makeError/makeErrorFromDefinition factories (via ErrorFactoryOptions), and parse(), while introducing explicitClass on ParsedError to distinguish producer-metadata classification from registry fallback.

Files Change
packages/errors/src/error.ts Adds optional cause to the ConstructiveError constructor and retains the original input as the native cause in toError().
packages/errors/src/factory.ts Accepts ErrorFactoryOptions with cause and forwards it when constructing errors.
packages/errors/src/parse.ts Populates explicitClass only when a valid producer class is actually consumed by classification.
packages/errors/src/types.ts Extends the public ParsedError and factory-option type surface with the new fields.
packages/errors/__tests__/cause-provenance.test.ts Covers cause preservation, serialization exclusion, producer classification precedence, and factory options.

No defects exceeded the reporting threshold after adjudication; the conditional spreads, native Error.cause handling, and classification precedence are correct, and cause stays excluded from toExtensions() and JSON serialization.

Reviewed commit: 0b47e76

@Zetazzz Zetazzz changed the title feat(errors): preserve causes and expose producer classification feat(errors): expose producer classification Sep 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant