Skip to content

driver-sql's inline unique-violation regex is a fourth private vocabulary — migrate it onto the shared @objectstack/types predicate #6543

Description

@os-project-manager

Blocked-by: #6250 (the shared predicate must land first — PR #6541)

Filed by the #6250 developer agent per that issue's ruling: "OUT OF SCOPE — the two out-of-lane consumers. ... packages/drivers/driver-sql/** (domain:drivers) must NOT be edited. Migrating them onto the predicate is a follow-up per lane, filed once the predicate exists." The predicate now exists, so this is that filing.

What is left

packages/drivers/driver-sql/src/sql-driver.ts judges the same question with an inline regex, no name and no doc comment:

if (nullSafe.size > 0 && /unique constraint failed|duplicate entry|duplicate key value/i.test(msg)) {

It reads only err.message — the code / errno channel is not consulted at all, so a driver that surfaces SQLSTATE 23505 or ER_DUP_ENTRY with unremarkable prose is invisible to it. That is the same blind spot #6250 measured on the REST side (a Postgres error carrying only code: '23505' came back 500), one layer down.

Why this is finding and not a defect

Nothing a user hits today, as far as this card measured: on the three dialects the repo ships, the message channel happens to carry the words. The defect is structural — a fourth vocabulary that can be taught a dialect the other three never learn. Grade it in triage rather than trusting the label.

The migration

@objectstack/driver-sql already depends on @objectstack/types. Swap for isUniqueViolationError(error) and delete the inline regex. Two things to check while there, because they are what makes this more than a mechanical swap:

  1. This site tests msg, not the error object. The shared predicate accepts a bare string on the message channel, so a minimal swap works — but passing the error instead is what buys the code/errno channels, which is the point of migrating.
  2. The nullSafe.size > 0 guard is the site's own business logic and must survive untouched; only the discriminator moves.

Note the sibling spelling in this package's own tests (/UNIQUE constraint failed|duplicate key value/, in sql-driver-schema.test.ts, sql-driver-unique-tenancy.test.ts, adr0120-three-posture-conformance.test.ts). Those are assertions on what a real driver emitted, not a discriminator, so they are arguably fine as-is — but they are a fifth spelling of the same vocabulary, and worth a decision in the same pass rather than left to the next reader.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions