Skip to content

refactor(errors): explicit codes on the generic error path, cause support, namespace remaps (TML-3180) - #29919

Merged
wmadden-electric merged 14 commits into
mainfrom
tml-3180-base-type-repairs
Aug 7, 2026
Merged

wmadden-electric merged 14 commits into
mainfrom
tml-3180-base-type-repairs

Conversation

@wmadden-electric

@wmadden-electric wmadden-electric commented Aug 7, 2026 •

Copy link
Copy Markdown
Contributor

Before this PR, a dozen CLI failures reported the wrong error code. errorRuntime hardcoded CONTRACT.VERIFY_FAILED, so call sites that needed a different code smuggled the real one into metadata:

// before — the envelope says CONTRACT.VERIFY_FAILED; the truth hides in meta
return errorRuntime(`Cannot set ref to the empty-database sentinel: ${hash}`, {
  meta: { code: 'MIGRATION.REF_SET_EMPTY_SENTINEL', hash },
});

// after — the envelope carries the code consumers branch on
return errorRuntime('MIGRATION.REF_SET_EMPTY_SENTINEL', `Cannot set ref to the empty-database sentinel: ${hash}`, {
  meta: { hash },
});

envelope.code is the stable machine-branching surface (ADR 239) — for those failures it was lying, and anything branching on it had to know a secret meta.code fallback. 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, the MIGRATION.REF_* resolution family, …), and the one site that legitimately meant CONTRACT.VERIFY_FAILED restates its defaults explicitly. meta.code no longer appears in production source; the Postgres driver's SQLSTATE moved to meta.sqlState so the key reads as a defect wherever it survives.

2. cause support on CliStructuredError. The class accepted no cause, so every catch that built a structured error dropped the underlying failure. It now forwards cause to Error; 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.*, and ADAPTER.* 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 detached origin/main checkout and reproduces identically there. lint:casts and lint:throws deltas 0 (MigrationToolsError.code narrowed 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.code and now read envelope.code — the behavior change is the point. Structural meta assertions were preserved.

Known

CI is red on main today (an unrelated driver-SPI drift in the supabase extension, plus DRIVER.PREPARE_FAILED missing 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, a fix line on one new site, a defensive copy in mapMigrationToolsError, an ADR 207 example code, and a dead test-type field.

Refs: TML-3180

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Improvements

    • Standardized structured error codes across CLI, migration, runtime, database, and connection operations.
    • Error responses now expose codes consistently at the top level while retaining diagnostic metadata.
    • Improved diagnostics by preserving underlying causes where available.
    • Added clearer categorization for manifest, migration, contract, connection, codec, and unsupported-feature failures.
  • Documentation

    • Expanded the error reference with new codes and examples.
    • Clarified error namespace conventions and CLI capability messages.

@wmadden-electric
wmadden-electric requested a review from a team as a code owner August 7, 2026 10:11
@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@coderabbitai

coderabbitai Bot commented Aug 7, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It 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 reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro Plus

Run ID: 1e4737c7-79bd-4146-9bac-97bed07925a9

📥 Commits

Reviewing files that changed from the base of the PR and between a37f50e and 91f9be7.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (1)
  • docs/reference/error-reference.md
🚧 Files skipped from review as they are similar to previous changes (1)
  • docs/reference/error-reference.md

📝 Walkthrough

Walkthrough

This 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.

Changes

Structured error envelope standardization

Layer / File(s) Summary
Core and migration error contracts
packages/1-framework/1-core/errors/*, packages/1-framework/3-tooling/migration/*
Structured errors now support dotted codes, optional causes, meta payloads, and shared migration error identification.
CLI error routing and validation
packages/1-framework/3-tooling/cli/src/*, packages/1-framework/3-tooling/cli/test/*, test/integration/test/*
CLI commands assign explicit codes, preserve migration errors, forward causes, and validate top-level envelope codes.
Runtime, driver, and target categories
packages/2-sql/*, packages/3-mongo-target/*, packages/3-targets/*
AST, codec, adapter, and connection failures use generalized RUNTIME.* or DRIVER.* codes with target metadata.
Error namespace documentation
docs/architecture docs/adrs/*, docs/reference/error-reference.md
ADRs and the reference document describe namespace rules and the expanded error catalog.

Estimated code review effort: 4 (Complex) | ~45 minutes

Possibly related PRs

Suggested labels: lgtm

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 23.53% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main changes: explicit error codes, cause support, and namespace remapping.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch tml-3180-base-type-repairs

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@pkg-pr-new

pkg-pr-new Bot commented Aug 7, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

prisma-next

npm i https://pkg.pr.new/prisma-next@29919

@prisma/orm-extension-arktype-json

npm i https://pkg.pr.new/@prisma/orm-extension-arktype-json@29919

@prisma/orm-extension-middleware-cache

npm i https://pkg.pr.new/@prisma/orm-extension-middleware-cache@29919

@prisma/orm-extension-paradedb

npm i https://pkg.pr.new/@prisma/orm-extension-paradedb@29919

@prisma/orm-extension-pgvector

npm i https://pkg.pr.new/@prisma/orm-extension-pgvector@29919

@prisma/orm-extension-postgis

npm i https://pkg.pr.new/@prisma/orm-extension-postgis@29919

@prisma/orm-extension-supabase

npm i https://pkg.pr.new/@prisma/orm-extension-supabase@29919

@prisma/orm-family-mongo

npm i https://pkg.pr.new/@prisma/orm-family-mongo@29919

@prisma/orm-family-sql

npm i https://pkg.pr.new/@prisma/orm-family-sql@29919

@prisma/orm-framework

npm i https://pkg.pr.new/@prisma/orm-framework@29919

@prisma/orm-mongo

npm i https://pkg.pr.new/@prisma/orm-mongo@29919

@prisma/orm-postgres

npm i https://pkg.pr.new/@prisma/orm-postgres@29919

@prisma/orm-sqlite

npm i https://pkg.pr.new/@prisma/orm-sqlite@29919

@prisma/orm-target-mongo

npm i https://pkg.pr.new/@prisma/orm-target-mongo@29919

@prisma/orm-target-postgres

npm i https://pkg.pr.new/@prisma/orm-target-postgres@29919

@prisma/orm-target-sqlite

npm i https://pkg.pr.new/@prisma/orm-target-sqlite@29919

@prisma/orm-toolchain

npm i https://pkg.pr.new/@prisma/orm-toolchain@29919

commit: 91f9be7

@github-actions

github-actions Bot commented Aug 7, 2026 •

Copy link
Copy Markdown
Contributor

size-limit report 📦

Path Size
postgres / no-emit 167.41 KB (+0.02% 🔺)
postgres / emit 145.59 KB (+0.03% 🔺)
mongo / no-emit 100.42 KB (+0.02% 🔺)
mongo / emit 90.25 KB (0%)
cf-worker / no-emit 192.04 KB (+0.02% 🔺)
cf-worker / emit 167.87 KB (+0.02% 🔺)

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 7991937 and a3cf2b6.

📒 Files selected for processing (58)
  • docs/architecture docs/adrs/ADR 207 - Family-instance capability views for the framework CLI.md
  • docs/architecture docs/adrs/ADR 239 - Errors are structural envelopes with dotted namespace codes.md
  • docs/reference/error-reference.md
  • packages/1-framework/1-core/errors/src/control.ts
  • packages/1-framework/1-core/errors/src/execution.ts
  • packages/1-framework/1-core/errors/test/control.test.ts
  • packages/1-framework/1-core/errors/test/execution.test.ts
  • packages/1-framework/3-tooling/cli/src/commands/contract-infer.ts
  • packages/1-framework/3-tooling/cli/src/commands/db-init.ts
  • packages/1-framework/3-tooling/cli/src/commands/db-sign.ts
  • packages/1-framework/3-tooling/cli/src/commands/db-verify.ts
  • packages/1-framework/3-tooling/cli/src/commands/migrate.ts
  • packages/1-framework/3-tooling/cli/src/commands/migration-check.ts
  • packages/1-framework/3-tooling/cli/src/commands/migration-new.ts
  • packages/1-framework/3-tooling/cli/src/commands/migration-show.ts
  • packages/1-framework/3-tooling/cli/src/commands/ref.ts
  • packages/1-framework/3-tooling/cli/src/control-api/operations/contract-emit.ts
  • packages/1-framework/3-tooling/cli/src/control-api/operations/format.ts
  • packages/1-framework/3-tooling/cli/src/utils/cli-errors.ts
  • packages/1-framework/3-tooling/cli/src/utils/command-helpers.ts
  • packages/1-framework/3-tooling/cli/src/utils/migration-path-target.ts
  • packages/1-framework/3-tooling/cli/src/utils/project-import-root.ts
  • packages/1-framework/3-tooling/cli/test/cli-errors.test.ts
  • packages/1-framework/3-tooling/cli/test/commands/migration-check-multi-space-command.test.ts
  • packages/1-framework/3-tooling/cli/test/commands/migration-check-multi-space.test.ts
  • packages/1-framework/3-tooling/cli/test/commands/migration-check-ref-error.test.ts
  • packages/1-framework/3-tooling/cli/test/commands/migration-check-single-target-multi-space.test.ts
  • packages/1-framework/3-tooling/cli/test/commands/migration-invariants.test.ts
  • packages/1-framework/3-tooling/cli/test/commands/migration-legend-commands.test.ts
  • packages/1-framework/3-tooling/cli/test/commands/migration-list.test.ts
  • packages/1-framework/3-tooling/cli/test/commands/migration-read-commands-parity.test.ts
  • packages/1-framework/3-tooling/cli/test/commands/migration-ref-error-mapping.test.ts
  • packages/1-framework/3-tooling/cli/test/commands/ref.test.ts
  • packages/1-framework/3-tooling/cli/test/control-api/contract-emit.test.ts
  • packages/1-framework/3-tooling/cli/test/output.errors.test.ts
  • packages/1-framework/3-tooling/cli/test/utils/aggregate-loader-preflight.test.ts
  • packages/1-framework/3-tooling/cli/test/utils/legend.test.ts
  • packages/1-framework/3-tooling/cli/test/utils/plan-resolution.test.ts
  • packages/1-framework/3-tooling/migration/src/errors.ts
  • packages/2-sql/4-lanes/relational-core/src/ast/types.ts
  • packages/2-sql/4-lanes/relational-core/test/ast/scalar-projection-expressions.test.ts
  • packages/2-sql/4-lanes/relational-core/test/ast/select.test.ts
  • packages/3-mongo-target/3-mongo-driver/src/exports/control.ts
  • packages/3-targets/3-targets/postgres/src/core/codec-descriptor.ts
  • packages/3-targets/3-targets/postgres/test/postgres-codec-descriptor.test.ts
  • packages/3-targets/3-targets/sqlite/src/core/codec-descriptor.ts
  • packages/3-targets/3-targets/sqlite/test/sqlite-codec-descriptor.test.ts
  • packages/3-targets/6-adapters/sqlite/src/core/adapter.ts
  • packages/3-targets/6-adapters/sqlite/test/adapter.test.ts
  • packages/3-targets/7-drivers/postgres/src/exports/control.ts
  • packages/3-targets/7-drivers/sqlite/src/core/control-driver.ts
  • test/integration/test/cli-journeys/invariant-routing.e2e.test.ts
  • test/integration/test/cli-journeys/invariant-routing.mongo.e2e.test.ts
  • test/integration/test/cli.db-init.e2e.errors.test.ts
  • test/integration/test/cli.db-ref-advancement.e2e.test.ts
  • test/integration/test/cli.migrate-drift-check.e2e.test.ts
  • test/integration/test/cli.migrate-ref-advancement.e2e.test.ts
  • test/integration/test/cli.migration-plan-ref-aware.e2e.test.ts

Comment thread docs/reference/error-reference.md Resolved

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between a3cf2b6 and 2f6d395.

📒 Files selected for processing (5)
  • docs/architecture docs/adrs/ADR 207 - Family-instance capability views for the framework CLI.md
  • docs/reference/error-reference.md
  • packages/1-framework/3-tooling/cli/src/commands/migrate.ts
  • packages/1-framework/3-tooling/cli/src/utils/cli-errors.ts
  • test/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

Comment thread docs/reference/error-reference.md Resolved
wmadden-electric added a commit that referenced this pull request Aug 7, 2026
… 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]>

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 2f6d395 and 7acf540.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (34)
  • packages/1-framework/1-core/errors/src/control.ts
  • packages/1-framework/3-tooling/cli/src/commands/db-init.ts
  • packages/1-framework/3-tooling/cli/src/commands/db-sign.ts
  • packages/1-framework/3-tooling/cli/src/commands/db-update.ts
  • packages/1-framework/3-tooling/cli/src/commands/migrate.ts
  • packages/1-framework/3-tooling/cli/src/commands/migration-log.ts
  • packages/1-framework/3-tooling/cli/src/commands/migration-plan.ts
  • packages/1-framework/3-tooling/cli/src/commands/migration-status.ts
  • packages/1-framework/3-tooling/cli/src/commands/ref.ts
  • packages/1-framework/3-tooling/cli/src/migration-cli.ts
  • packages/1-framework/3-tooling/cli/src/utils/cli-errors.ts
  • packages/1-framework/3-tooling/cli/src/utils/contract-at-errors.ts
  • packages/1-framework/3-tooling/cli/src/utils/contract-space-aggregate-loader.ts
  • packages/1-framework/3-tooling/cli/src/utils/plan-resolution.ts
  • packages/1-framework/3-tooling/cli/test/commands/db-update-read-aggregate-json-golden.test.ts
  • packages/1-framework/3-tooling/cli/test/commands/migration-plan-command.test.ts
  • packages/1-framework/3-tooling/cli/test/commands/migration-plan.test.ts
  • packages/1-framework/3-tooling/cli/test/commands/migration-ref-error-mapping.test.ts
  • packages/1-framework/3-tooling/cli/test/commands/migration-tamper.test.ts
  • packages/1-framework/3-tooling/cli/test/utils/aggregate-loader-preflight.test.ts
  • packages/1-framework/3-tooling/cli/test/utils/plan-resolution.test.ts
  • packages/1-framework/3-tooling/migration/package.json
  • packages/1-framework/3-tooling/migration/src/assert-descriptor-self-consistency.ts
  • packages/1-framework/3-tooling/migration/src/errors.ts
  • packages/1-framework/3-tooling/migration/src/io.ts
  • packages/1-framework/3-tooling/migration/src/refs.ts
  • packages/1-framework/3-tooling/migration/test/aggregate/contract-at.test.ts
  • packages/1-framework/3-tooling/migration/test/assert-descriptor-self-consistency.test.ts
  • packages/1-framework/3-tooling/migration/test/errors.test.ts
  • packages/1-framework/3-tooling/migration/test/graph-membership.test.ts
  • packages/1-framework/3-tooling/migration/test/invariants.test.ts
  • packages/1-framework/3-tooling/migration/test/io.test.ts
  • packages/1-framework/3-tooling/migration/test/migration-base.test.ts
  • packages/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

wmadden-electric added a commit that referenced this pull request Aug 7, 2026
…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]>
wmadden-electric added a commit that referenced this pull request Aug 7, 2026
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]>
wmadden-electric added a commit that referenced this pull request Aug 7, 2026
…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]>
wmadden-electric added a commit that referenced this pull request Aug 7, 2026
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]>
@wmadden-electric
wmadden-electric force-pushed the tml-3180-base-type-repairs branch from 7acf540 to a37f50e Compare August 7, 2026 12:03
wmadden-electric and others added 14 commits August 7, 2026 16:27
…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]>
@wmadden-electric
wmadden-electric force-pushed the tml-3180-base-type-repairs branch from a37f50e to 91f9be7 Compare August 7, 2026 14:28
@wmadden-electric
wmadden-electric added this pull request to the merge queue Aug 7, 2026
Merged via the queue into main with commit 71234cb Aug 7, 2026
24 of 27 checks passed
@wmadden-electric
wmadden-electric deleted the tml-3180-base-type-repairs branch August 7, 2026 15:08
wmadden-electric added a commit that referenced this pull request Aug 7, 2026
…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]>
Thegreatsura pushed a commit to Thegreatsura/prisma that referenced this pull request Aug 8, 2026
…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]>
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.

3 participants