Repository navigation
refactor(errors): explicit codes on the generic error path, cause support, namespace remaps (TML-3180) - #29919
Conversation
|
|
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yml Review profile: CHILL Plan: Pro Plus Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughThis PR standardizes structured error envelopes across framework, CLI, migration tooling, SQL AST validation, target codecs, and database drivers. It moves codes to the top-level envelope, preserves causes, updates error routing and tests, and expands error documentation. ChangesStructured error envelope standardization
Estimated code review effort: 4 (Complex) | ~45 minutes Possibly related PRs
Suggested labels: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
prisma-next
@prisma/orm-extension-arktype-json
@prisma/orm-extension-middleware-cache
@prisma/orm-extension-paradedb
@prisma/orm-extension-pgvector
@prisma/orm-extension-postgis
@prisma/orm-extension-supabase
@prisma/orm-family-mongo
@prisma/orm-family-sql
@prisma/orm-framework
@prisma/orm-mongo
@prisma/orm-postgres
@prisma/orm-sqlite
@prisma/orm-target-mongo
@prisma/orm-target-postgres
@prisma/orm-target-sqlite
@prisma/orm-toolchain
commit: |
size-limit report 📦
|
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@docs/reference/error-reference.md`:
- Around line 1042-1045: Update the MIGRATION.TARGET_NOT_APP_SPACE description
to state that filesystem-path targets must resolve to an app-space migration
directory, excluding the app-space root itself, rather than only describing
targets outside the migrations directory.
In `@packages/1-framework/1-core/errors/src/execution.ts`:
- Around line 235-242: Propagate the underlying runner cause through the
MigrateFailure mappings in migrate.ts, db-init.ts, and db-update.ts: add cause
to the relevant failure shapes/envelopes and map the source failure’s cause
alongside summary, why, and meta. Ensure the resulting errorRunnerFailed call
receives { cause } so RUNNER_FAILED preserves the original error.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yml
Review profile: CHILL
Plan: Pro Plus
Run ID: ec8df3b8-8be1-45f4-a5a4-632c53eca3c4
📒 Files selected for processing (58)
docs/architecture docs/adrs/ADR 207 - Family-instance capability views for the framework CLI.mddocs/architecture docs/adrs/ADR 239 - Errors are structural envelopes with dotted namespace codes.mddocs/reference/error-reference.mdpackages/1-framework/1-core/errors/src/control.tspackages/1-framework/1-core/errors/src/execution.tspackages/1-framework/1-core/errors/test/control.test.tspackages/1-framework/1-core/errors/test/execution.test.tspackages/1-framework/3-tooling/cli/src/commands/contract-infer.tspackages/1-framework/3-tooling/cli/src/commands/db-init.tspackages/1-framework/3-tooling/cli/src/commands/db-sign.tspackages/1-framework/3-tooling/cli/src/commands/db-verify.tspackages/1-framework/3-tooling/cli/src/commands/migrate.tspackages/1-framework/3-tooling/cli/src/commands/migration-check.tspackages/1-framework/3-tooling/cli/src/commands/migration-new.tspackages/1-framework/3-tooling/cli/src/commands/migration-show.tspackages/1-framework/3-tooling/cli/src/commands/ref.tspackages/1-framework/3-tooling/cli/src/control-api/operations/contract-emit.tspackages/1-framework/3-tooling/cli/src/control-api/operations/format.tspackages/1-framework/3-tooling/cli/src/utils/cli-errors.tspackages/1-framework/3-tooling/cli/src/utils/command-helpers.tspackages/1-framework/3-tooling/cli/src/utils/migration-path-target.tspackages/1-framework/3-tooling/cli/src/utils/project-import-root.tspackages/1-framework/3-tooling/cli/test/cli-errors.test.tspackages/1-framework/3-tooling/cli/test/commands/migration-check-multi-space-command.test.tspackages/1-framework/3-tooling/cli/test/commands/migration-check-multi-space.test.tspackages/1-framework/3-tooling/cli/test/commands/migration-check-ref-error.test.tspackages/1-framework/3-tooling/cli/test/commands/migration-check-single-target-multi-space.test.tspackages/1-framework/3-tooling/cli/test/commands/migration-invariants.test.tspackages/1-framework/3-tooling/cli/test/commands/migration-legend-commands.test.tspackages/1-framework/3-tooling/cli/test/commands/migration-list.test.tspackages/1-framework/3-tooling/cli/test/commands/migration-read-commands-parity.test.tspackages/1-framework/3-tooling/cli/test/commands/migration-ref-error-mapping.test.tspackages/1-framework/3-tooling/cli/test/commands/ref.test.tspackages/1-framework/3-tooling/cli/test/control-api/contract-emit.test.tspackages/1-framework/3-tooling/cli/test/output.errors.test.tspackages/1-framework/3-tooling/cli/test/utils/aggregate-loader-preflight.test.tspackages/1-framework/3-tooling/cli/test/utils/legend.test.tspackages/1-framework/3-tooling/cli/test/utils/plan-resolution.test.tspackages/1-framework/3-tooling/migration/src/errors.tspackages/2-sql/4-lanes/relational-core/src/ast/types.tspackages/2-sql/4-lanes/relational-core/test/ast/scalar-projection-expressions.test.tspackages/2-sql/4-lanes/relational-core/test/ast/select.test.tspackages/3-mongo-target/3-mongo-driver/src/exports/control.tspackages/3-targets/3-targets/postgres/src/core/codec-descriptor.tspackages/3-targets/3-targets/postgres/test/postgres-codec-descriptor.test.tspackages/3-targets/3-targets/sqlite/src/core/codec-descriptor.tspackages/3-targets/3-targets/sqlite/test/sqlite-codec-descriptor.test.tspackages/3-targets/6-adapters/sqlite/src/core/adapter.tspackages/3-targets/6-adapters/sqlite/test/adapter.test.tspackages/3-targets/7-drivers/postgres/src/exports/control.tspackages/3-targets/7-drivers/sqlite/src/core/control-driver.tstest/integration/test/cli-journeys/invariant-routing.e2e.test.tstest/integration/test/cli-journeys/invariant-routing.mongo.e2e.test.tstest/integration/test/cli.db-init.e2e.errors.test.tstest/integration/test/cli.db-ref-advancement.e2e.test.tstest/integration/test/cli.migrate-drift-check.e2e.test.tstest/integration/test/cli.migrate-ref-advancement.e2e.test.tstest/integration/test/cli.migration-plan-ref-aware.e2e.test.ts
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@docs/reference/error-reference.md`:
- Line 1016: Update the MIGRATION.RUNNER_FAILED documentation entry to use
generic remediation for unclassified runner failures from migrate and db init.
Restrict conflict-specific guidance to a separately identified conflict
condition, if one exists; otherwise replace the current schema-drift instruction
with neutral guidance to inspect the wrapped failure details and metadata.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yml
Review profile: CHILL
Plan: Pro Plus
Run ID: c8433197-d7f9-4a84-8fa6-26f3636de83f
📒 Files selected for processing (5)
docs/architecture docs/adrs/ADR 207 - Family-instance capability views for the framework CLI.mddocs/reference/error-reference.mdpackages/1-framework/3-tooling/cli/src/commands/migrate.tspackages/1-framework/3-tooling/cli/src/utils/cli-errors.tstest/integration/test/cli.migration-plan-ref-aware.e2e.test.ts
💤 Files with no reviewable changes (1)
- test/integration/test/cli.migration-plan-ref-aware.e2e.test.ts
🚧 Files skipped from review as they are similar to previous changes (3)
- packages/1-framework/3-tooling/cli/src/commands/migrate.ts
- docs/architecture docs/adrs/ADR 207 - Family-instance capability views for the framework CLI.md
- packages/1-framework/3-tooling/cli/src/utils/cli-errors.ts
… base type Operator directive: one error base type and one result type on #29919. The Result type already holds; this addendum makes MigrationToolsError extend CliStructuredError, renames details to meta, rewrites the predicate without the name check, and deletes the boundary mapper. Refs: TML-3180 Co-Authored-By: Claude Fable 5 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In
`@packages/1-framework/3-tooling/cli/test/commands/db-update-read-aggregate-json-golden.test.ts`:
- Around line 143-164: Move cleanup for the mocks created by setupCommandMocks
into a finally block surrounding command creation and execution in this test,
ensuring cleanup runs for expected process.exit handling and unexpected errors
before rethrowing. Preserve the existing exitCode behavior and assertions.
In `@packages/1-framework/3-tooling/migration/src/errors.ts`:
- Around line 57-63: Update the is method of MigrationToolsError to remove the
bare MigrationToolsError cast; after CliStructuredError.is(error), narrow
category using a property-presence check before comparing it to 'MIGRATION',
then read error.code only after the existing structured-error guard.
- Around line 38-55: Remove the Biome suppression above MigrationToolsError’s
constructor and move category initialization into the constructor so it performs
required initialization while preserving the MIGRATION value and existing
required why/fix options.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yml
Review profile: CHILL
Plan: Pro Plus
Run ID: 340389ae-0854-49a3-87d5-9e1768ab7d85
⛔ Files ignored due to path filters (1)
pnpm-lock.yamlis excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (34)
packages/1-framework/1-core/errors/src/control.tspackages/1-framework/3-tooling/cli/src/commands/db-init.tspackages/1-framework/3-tooling/cli/src/commands/db-sign.tspackages/1-framework/3-tooling/cli/src/commands/db-update.tspackages/1-framework/3-tooling/cli/src/commands/migrate.tspackages/1-framework/3-tooling/cli/src/commands/migration-log.tspackages/1-framework/3-tooling/cli/src/commands/migration-plan.tspackages/1-framework/3-tooling/cli/src/commands/migration-status.tspackages/1-framework/3-tooling/cli/src/commands/ref.tspackages/1-framework/3-tooling/cli/src/migration-cli.tspackages/1-framework/3-tooling/cli/src/utils/cli-errors.tspackages/1-framework/3-tooling/cli/src/utils/contract-at-errors.tspackages/1-framework/3-tooling/cli/src/utils/contract-space-aggregate-loader.tspackages/1-framework/3-tooling/cli/src/utils/plan-resolution.tspackages/1-framework/3-tooling/cli/test/commands/db-update-read-aggregate-json-golden.test.tspackages/1-framework/3-tooling/cli/test/commands/migration-plan-command.test.tspackages/1-framework/3-tooling/cli/test/commands/migration-plan.test.tspackages/1-framework/3-tooling/cli/test/commands/migration-ref-error-mapping.test.tspackages/1-framework/3-tooling/cli/test/commands/migration-tamper.test.tspackages/1-framework/3-tooling/cli/test/utils/aggregate-loader-preflight.test.tspackages/1-framework/3-tooling/cli/test/utils/plan-resolution.test.tspackages/1-framework/3-tooling/migration/package.jsonpackages/1-framework/3-tooling/migration/src/assert-descriptor-self-consistency.tspackages/1-framework/3-tooling/migration/src/errors.tspackages/1-framework/3-tooling/migration/src/io.tspackages/1-framework/3-tooling/migration/src/refs.tspackages/1-framework/3-tooling/migration/test/aggregate/contract-at.test.tspackages/1-framework/3-tooling/migration/test/assert-descriptor-self-consistency.test.tspackages/1-framework/3-tooling/migration/test/errors.test.tspackages/1-framework/3-tooling/migration/test/graph-membership.test.tspackages/1-framework/3-tooling/migration/test/invariants.test.tspackages/1-framework/3-tooling/migration/test/io.test.tspackages/1-framework/3-tooling/migration/test/migration-base.test.tspackages/1-framework/3-tooling/migration/test/migration-graph.test.ts
💤 Files with no reviewable changes (1)
- packages/1-framework/3-tooling/cli/src/commands/migration-plan.ts
🚧 Files skipped from review as they are similar to previous changes (4)
- packages/1-framework/3-tooling/cli/src/commands/db-sign.ts
- packages/1-framework/3-tooling/cli/test/commands/migration-ref-error-mapping.test.ts
- packages/1-framework/3-tooling/cli/test/utils/aggregate-loader-preflight.test.ts
- packages/1-framework/1-core/errors/src/control.ts
…onToolsError Assign category inside the constructor instead of a field initializer so the constructor has required behavior and the noUselessConstructor suppression goes away, and narrow with a property-presence check in is() instead of a bare as cast. Behavior unchanged. Addresses two review threads on PR #29919. Co-Authored-By: Claude Fable 5 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
The RUNNER_FAILED mappings in migrate, db init, and db update flattened
the runner's failure into summary/why/meta and dropped the original
object. RunnerFailure, MigrateFailure, DbInitFailure, and DbUpdateFailure
gain an optional cause; runMigration attaches the runner's failure object
verbatim, and the command mappers pass it to errorRunnerFailed(..., {
cause }). Envelopes are unchanged — cause is never serialized. A unit
test pins the runMigration failure path.
Addresses a review thread on PR #29919.
Co-Authored-By: Claude Fable 5 <[email protected]>
Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
…pe pin An unexpected throw from executeCommand rethrew before cleanup() ran, leaking the process.exit/stream/TTY mocks into later tests. Addresses a review thread on PR #29919. Co-Authored-By: Claude Fable 5 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
MIGRATION.RUNNER_FAILED: replace the conflict-specific remediation with generic guidance — the code covers unclassified runner failures, not just schema conflicts. MIGRATION.TARGET_NOT_APP_SPACE: state that the target must resolve to an app-space migration directory; resolveAppTargetPath also rejects the app-space migrations root itself. Addresses two review threads on PR #29919. Co-Authored-By: Claude Fable 5 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
7acf540 to
a37f50e
Compare
…ories Constructor options gain cause (forwarded to Error via ES2022 options); errorUnexpected, errorRunnerFailed, errorMarkerRowCorrupt, errorMarkerReadFailed, and the legacy-marker-shape path forward it. rethrowMarkerReadError attaches the original error as cause on all three mapping branches. Envelope shape unchanged. Refs: TML-3180 Co-Authored-By: Claude Fable 5 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…ing codes in meta
errorRuntime(code, summary, options) replaces the CONTRACT.VERIFY_FAILED
hardcode. Every call site now names its real code: drivers raise
DRIVER.CONNECTION_FAILED (postgres SQLSTATE moves to meta.sqlState),
the cli-errors factories promote their meta.code literals to envelope
codes, mapRefResolutionError gets the MIGRATION.REF_* family,
mapMigrationToolsError forwards error.code (typed MIGRATION.${string})
with the original error as cause, and db verify restates the old
verify defaults under a narrowed CONTRACT.VERIFY_FAILED. New codes are
documented in the error reference; smuggled-site tests assert
envelope.code instead of meta.code.
Refs: TML-3180
Co-Authored-By: Claude Fable 5 <[email protected]>
Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
…spaces SQL.AST_INVALID becomes RUNTIME.AST_INVALID; the SQLITE./POSTGRES. codec descriptor codes become RUNTIME.CODEC_DESCRIPTOR_INVALID, RUNTIME.CODEC_DESCRIPTOR_ARRAY_UNSUPPORTED, and RUNTIME.DUPLICATE_CODEC (with meta.target); ADAPTER.CAPABILITY_MISSING becomes RUNTIME.AST_UNSUPPORTED with meta target/feature. None of the old codes were published, so the remaps are non-breaking. ADR 239 gains a "Targets and adapters" paragraph stating that target packages use core namespaces with the target as meta, and the error reference documents the two new RUNTIME codes. Refs: TML-3180 Co-Authored-By: Claude Fable 5 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…gnature Refs: TML-3180 Co-Authored-By: Claude Fable 5 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…y smuggled Follows the errorRuntime code promotion: invariant-routing (pg and mongo), ref-advancement, drift-check, and plan-ref-aware journeys now read the dotted code from the envelope top level. Refs: TML-3180 Co-Authored-By: Claude Fable 5 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…/catch Review finding: the cause-preservation tests could pass silently if the rethrow ever stopped throwing. Refs: TML-3180 Co-Authored-By: Claude Fable 5 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…aining review nits Nine error-reference entries gained producing sites in TML-3180 without their entries saying so; each now names the new site and its meta shape (worst was CONTRACT.INFER_UNSUPPORTED, which only described the shape-inference sites and not the capability-miss site). The MIGRATION.NO_INVARIANT_PATH site in migrate.ts gains the fix text from errorNoInvariantPath. mapMigrationToolsError copies error.details again instead of sharing the reference. ADR 207 stops inventing CLI.FAMILY_UNSUPPORTED and cites the real CONTRACT.INFER_UNSUPPORTED exemplar. The plan-ref-aware e2e test drops its dead meta.code field. Refs: TML-3180 Co-Authored-By: Claude Fable 5 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…details to meta MigrationToolsError is now a subclass of the common CliStructuredError base type (TML-3180 design addendum). The class no longer sets this.name, so boundary duck-typing (CliStructuredError.is) recognizes these errors; its own is() predicate now checks the base duck-type plus the MIGRATION category/code namespace instead of the name. The details constructor option, property, and every factory literal are renamed to meta — one vocabulary with the envelope. @internal/migration-tools gains a dependency on @internal/errors (3-tooling depending on 1-core; lint:deps stays green). New unit coverage pins the base-type shape (name, toEnvelope, is() narrowing) and that no factory passes identical why and fix, so the parent's fix-equals-why normalization never fires for these errors. Co-Authored-By: Claude Fable 5 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…rors through MigrationToolsError is now itself a CliStructuredError, so the CLI boundary mapper is obsolete: catch sites return notOk(error) directly and the migration-file CLI renders through the shared writeStructuredError surface. Branches made dead by the subtype relation (a MigrationToolsError check behind a CliStructuredError check) are removed. Sites that deliberately re-code into a command-specific envelope (mapContractAtError, plan-resolution's forgot-the-flag rewrite) keep doing so and now attach the original error as cause; errorContractValidationFailed, errorFileNotFound, errorSnapshotMissing, and errorPlanForgotTheFlag accept a cause option for this. --json envelopes are byte-identical before and after — the only behavioral delta is the disappearance of the mapper's self-referential cause, which never reached the envelope. Co-Authored-By: Claude Fable 5 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…s failure Command-level envelope pin for the db-sign/-update/-init consuming group: db update --advance-ref with an invalid ref name surfaces the MIGRATION.INVALID_REF_NAME MigrationToolsError byte-identical through --json (code, severity, summary, why, fix, meta). Completes the per-command-group pins alongside the existing migrate, migration-status, and ref envelope assertions. Co-Authored-By: Claude Fable 5 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…onToolsError Assign category inside the constructor instead of a field initializer so the constructor has required behavior and the noUselessConstructor suppression goes away, and narrow with a property-presence check in is() instead of a bare as cast. Behavior unchanged. Addresses two review threads on PR #29919. Co-Authored-By: Claude Fable 5 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
The RUNNER_FAILED mappings in migrate, db init, and db update flattened
the runner's failure into summary/why/meta and dropped the original
object. RunnerFailure, MigrateFailure, DbInitFailure, and DbUpdateFailure
gain an optional cause; runMigration attaches the runner's failure object
verbatim, and the command mappers pass it to errorRunnerFailed(..., {
cause }). Envelopes are unchanged — cause is never serialized. A unit
test pins the runMigration failure path.
Addresses a review thread on PR #29919.
Co-Authored-By: Claude Fable 5 <[email protected]>
Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
…pe pin An unexpected throw from executeCommand rethrew before cleanup() ran, leaking the process.exit/stream/TTY mocks into later tests. Addresses a review thread on PR #29919. Co-Authored-By: Claude Fable 5 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
MIGRATION.RUNNER_FAILED: replace the conflict-specific remediation with generic guidance — the code covers unclassified runner failures, not just schema conflicts. MIGRATION.TARGET_NOT_APP_SPACE: state that the target must resolve to an app-space migration directory; resolveAppTargetPath also rejects the app-space migrations root itself. Addresses two review threads on PR #29919. Co-Authored-By: Claude Fable 5 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
a37f50e to
91f9be7
Compare
…ypes The rebase onto main (PR #29919 merged) left three sites still using the deleted mapMigrationToolsError: the emitted-contract deserialization mappings in contract-snapshot-resolution and the migration-plan prologue guard's MigrationToolsError branch (now dead — CliStructuredError.is matches the subclass). All are direct passthrough now, and envelope assertions read the top-level code instead of the old meta-smuggled one. This also upgrades the earlier review fix at the emitted-contract boundary to the original review intent: main now supports cause, so the ENOENT, unexpected-read, and JSON-parse failure sites attach the underlying error as cause (MigrationToolsError and errorContractDeserializationFailed gain an optional cause for this); the path stays in the message. The shape-failure site has no underlying throwable and carries none. Co-Authored-By: Claude Fable 5 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…r on results (prisma#29925) Extracts the durable decisions from the consolidate-clis (TML-3172) Drive project into a repo ADR, so the project's working artifacts (decision-record branch, PR prisma#29917) can be discarded rather than merged. Records: errors structured at origin with no catch-all codes; `envelope.code` as the only machine-branching surface (explicit-code `errorRuntime`, no `meta.code`); the shared `Result` shape with the single `ok` discriminator; and the `MigrationToolsError` collapse into `CliStructuredError`. All already implemented on main via prisma#29919 and prisma#29911; composer's siblings are its ADR-0043/0044 (merged in prisma/composer#205). 🤖 Generated with [Claude Code](https://claude.com/claude-code) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Documentation** * Added an architecture decision record documenting standardized structured errors and explicit, machine-readable error codes. * Clarified consistent operation result handling through a single success/failure indicator. * Documented unified error hierarchies, preserved error causes, direct error propagation, and guidance for maintaining error references. * Updated the architecture decision record index to include the new guidance. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]> Co-authored-by: Claude Fable 5 <[email protected]>
Before this PR, a dozen CLI failures reported the wrong error code.
errorRuntimehardcodedCONTRACT.VERIFY_FAILED, so call sites that needed a different code smuggled the real one into metadata:envelope.codeis the stable machine-branching surface (ADR 239) — for those failures it was lying, and anything branching on it had to know a secretmeta.codefallback. This PR makes the code explicit at every construction site, and adds two related repairs the same foundation needs.The three repairs
1. The generic path takes a code.
errorRuntime(code, summary, options). All 43 production call sites audited and assigned their true code: the 12 that smuggled now declare what they always meant (MIGRATION.HASH_NOT_IN_GRAPH,SNAPSHOT_MISSING,MARKER_MISMATCH, …), the codeless ones get 14 new codes (DRIVER.CONNECTION_FAILED,CLI.PROJECT_MANIFEST_INVALID, theMIGRATION.REF_*resolution family, …), and the one site that legitimately meantCONTRACT.VERIFY_FAILEDrestates its defaults explicitly.meta.codeno longer appears in production source; the Postgres driver's SQLSTATE moved tometa.sqlStateso the key reads as a defect wherever it survives.2.
causesupport onCliStructuredError. The class accepted nocause, so everycatchthat built a structured error dropped the underlying failure. It now forwardscausetoError;toEnvelope()deliberately does not serialize it (a cause is for in-process consumers and logs, not the wire). Five factories that wrapped caught errors forward it; input validators with nothing to forward were left alone.3. Namespace drift.
SQL.*,SQLITE.*,POSTGRES.*, andADAPTER.*were in live use outside ADR 239's closed list — targets and adapters do not get namespaces of their own. They remap onto the concern namespaces already covering those conditions (RUNTIME.AST_INVALID,RUNTIME.AST_UNSUPPORTED,RUNTIME.DUPLICATE_CODEC+meta.target, plus two new codec-descriptor subcodes). None were published, so the remaps are non-breaking. ADR 239 gains a paragraph closing the gap that produced the drift.Why now
These are pre-freeze repairs: ADR 239 freezes the taxonomy at RC, and published codes cannot be renamed cheaply afterwards. They are also the precondition for sharing this error foundation across the other Prisma CLIs (the consolidate-clis project) — a foundation whose codes lie is not one to copy.
Verification
@internal/errors(99),@internal/cli(1,389),@internal/migration-tools(587), plus driver/target/adapter/relational-core suites — all green. Full integration suite: 1,811 passed; every remaining failure was re-run against a detachedorigin/maincheckout and reproduces identically there.lint:castsandlint:throwsdeltas 0 (MigrationToolsError.codenarrowed to a dotted template type, so the one tempting cast was unnecessary). Independently reviewed against the slice design.Test churn is concentrated in assertions that read
meta.codeand now readenvelope.code— the behavior change is the point. Structural meta assertions were preserved.Known
CI is red on
maintoday (an unrelated driver-SPI drift in the supabase extension, plusDRIVER.PREPARE_FAILEDmissing from the error reference); a separate fix is in flight. Six review nits are outstanding, tracked for a follow-up commit: producing-site updates for nine existing error-reference entries, afixline on one new site, a defensive copy inmapMigrationToolsError, an ADR 207 example code, and a dead test-type field.Refs: TML-3180
🤖 Generated with Claude Code
Summary by CodeRabbit
Improvements
Documentation