Skip to content

fix(cli): render Go's caret, Detail, and 42704 hint in migration-apply errors - #5967

Merged
Coly010 merged 2 commits into
developfrom
columferry/cli-1977-migration-apply-errors-omit-gos-caret-detail-and-42704
Jul 28, 2026
Merged

fix(cli): render Go's caret, Detail, and 42704 hint in migration-apply errors#5967
Coly010 merged 2 commits into
developfrom
columferry/cli-1977-migration-apply-errors-omit-gos-caret-detail-and-42704

Conversation

@Coly010

@Coly010 Coly010 commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

What changed

A failed migration statement in db push / db reset (remote migrate) / migration up|down now renders the same failure text as the Go CLI's (*MigrationFile).ExecBatch (apps/cli-go/pkg/migration/file.go:88-132), byte-for-byte:

ERROR: type "ltree" does not exist (SQLSTATE 42704)

Hint: This type may be defined in a schema that's not in your search_path.
      Use schema-qualified type references to avoid this error:
        CREATE TABLE example (col extensions.ltree);
      Learn more: supabase migration new --help
At statement: 0
CREATE TABLE test (path ltree NOT NULL)
                        ^

Previously the TS apply path emitted only <driver text>\nAt statement: <i>\n<stat> — and with the real driver the head line was literally effect/sql/SqlError: Failed to execute statement. No caret, no Detail, no 42704 hint.

  • Driver boundary (legacy-db-connection.sql-pg.layer.ts): a server ErrorResponse found on the SqlError cause chain is now rendered as pgconn's PgError.Error()<Severity>: <Message> (SQLSTATE <Code>) (pgconn errors.go:51) — and LegacyDbExecError carries the structured detail / position fields (detail only when non-empty, position only when > 0, matching Go's gates). Non-server failures keep the driver text verbatim.
  • Apply mapper (legacy-migration-apply.ts): legacyMarkError is a byte-faithful port of Go's markError — the server position is consumed against UTF-8 byte lengths (Go's len(line)), the caret line replaces every line after the error line (Go's append(lines[:j+1], caret) truncation), and position 0 / past-end / on-a-line-break leave the statement untouched. All semantics were pinned by running Go's markError directly on the same inputs. The Detail line and the SQLSTATE-42704 undefined-type hint block (gated on Go's typeNamePattern match + code 42704 + not schema-qualified) are reproduced with Go's exact ordering and indentation.
  • legacyIsSqlState is hoisted out of legacy-connect-errors.ts's private pattern so the connect-cause renderer and the exec-error mapper share the server-error discriminator.

Behavior notes

  • The pgconn-style head line applies to every session exec/query server error, not just migration apply — that is the correct owner (Go's session errors all bottom out in PgError.Error()). This incidentally improves the seed path too: failed to send batch: ERROR: … (SQLSTATE …) now matches Go's SeedFile.ExecBatchWithCache wrap more closely.
  • Known, unchanged divergence (out of scope): non-server exec failures (socket drops mid-statement) keep the node driver's own text, which cannot byte-match Go's pgx wording.
  • A new wire-level integration test drives the REAL driver stack (fake Postgres server → node-postgres DatabaseError@effect/sql-pg SqlError chain → the new mapper) so a future @effect/sql-pg/pg bump that changes the error wrapping fails CI instead of silently regressing to the opaque head line.

Review pass (architect / engineer / security / DX): all approve. Deliberately left open: terminal-escape passthrough of server-controlled error text is intended Go parity (Go prints the same fields raw to stderr); a describeLiveDataPlane golden-path test against a real backend was deemed redundant with the new wire-level test.

Fixes CLI-1977
https://linear.app/supabase/issue/CLI-1977/migration-apply-errors-omit-gos-caret-detail-and-42704-extension-hint

@Coly010

Coly010 commented Jul 28, 2026

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Chef's kiss.

Reviewed commit: edeac810b7

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@Coly010 Coly010 self-assigned this Jul 28, 2026
@Coly010
Coly010 marked this pull request as ready for review July 28, 2026 11:26
@Coly010
Coly010 requested a review from a team as a code owner July 28, 2026 11:26

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: edeac810b7

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread apps/cli/src/legacy/shared/legacy-db-connection.sql-pg.layer.ts
@github-actions

github-actions Bot commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Supabase CLI preview

npx --yes https://pkg.pr.new/supabase/cli/supabase@dd66eaef37cc2f14b1e5a5539da9c68b2e385b05

Preview package for commit dd66eae.

@Coly010

Coly010 commented Jul 28, 2026

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep it up!

Reviewed commit: dd66eaef37

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@kanadgupta kanadgupta 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.

This is neat!

@Coly010
Coly010 added this pull request to the merge queue Jul 28, 2026
Merged via the queue into develop with commit daf3c86 Jul 28, 2026
27 checks passed
@Coly010
Coly010 deleted the columferry/cli-1977-migration-apply-errors-omit-gos-caret-detail-and-42704 branch July 28, 2026 15:08
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.

2 participants