porsager / postgres

Postgres.js - The Fastest full featured PostgreSQL client for Node.js, Deno, Bun and CloudFlare
The Unlicense
7.09k stars 259 forks source link

Fatal error on unique constraint #773

Closed binajmen closed 6 months ago

binajmen commented 6 months ago

I'm using postgres in the context of a Remix application using Drizzle.

CREATE TABLE public.nouns (
    id varchar(13) NOT NULL,
    singular varchar(128) NOT NULL,
    plural varchar(128) NOT NULL,
    french varchar(128) NOT NULL,
    CONSTRAINT nouns_pkey PRIMARY KEY (id),
    CONSTRAINT nouns_singular_unique UNIQUE (singular)
);

I have an unique constraint on singular. When trying to insert a duplicate value, instead of a database error I could catch, I have the following fatal error:

node:internal/fs/utils:347
    throw err;
    ^

Error: ENOENT: no such file or directory, open '/Users/binajmen/Projects/vocabularium/node_modules/.pnpm/postgres@3.4.3/node_modules/postgres/src/connection.js.map'
    at Object.openSync (node:fs:600:3)
    at Object.readFileSync (node:fs:468:35)
    at Array.retrieveSourceMap (/Users/binajmen/Projects/vocabularium/node_modules/.pnpm/@remix-run+serve@2.4.1_typescript@5.3.3/node_modules/@remix-run/serve/dist/cli.js:50:37)
    at /Users/binajmen/Projects/vocabularium/node_modules/.pnpm/source-map-support@0.5.21/node_modules/source-map-support/source-map-support.js:85:24
    at mapSourcePosition (/Users/binajmen/Projects/vocabularium/node_modules/.pnpm/source-map-support@0.5.21/node_modules/source-map-support/source-map-support.js:216:21)
    at wrapCallSite (/Users/binajmen/Projects/vocabularium/node_modules/.pnpm/source-map-support@0.5.21/node_modules/source-map-support/source-map-support.js:397:20)
    at Function.prepareStackTrace (/Users/binajmen/Projects/vocabularium/node_modules/.pnpm/source-map-support@0.5.21/node_modules/source-map-support/source-map-support.js:446:39)
    at maybeOverridePrepareStackTrace (node:internal/errors:140:29)
    at prepareStackTrace (node:internal/errors:114:5)
    at process.emit (/Users/binajmen/Projects/vocabularium/node_modules/.pnpm/source-map-support@0.5.21/node_modules/source-map-support/source-map-support.js:508:52) {
  errno: -2,
  syscall: 'open',
  code: 'ENOENT',
  path: '/Users/binajmen/Projects/vocabularium/node_modules/.pnpm/postgres@3.4.3/node_modules/postgres/src/connection.js.map'
}

Node.js v18.14.1
{
    "drizzle-orm": "^0.29.3",
    "postgres": "^3.4.3",
}

Using a SQL client leads to the expected error message:

SQL Error [23505]: ERROR: duplicate key value violates unique constraint "nouns_singular_unique"
  Detail: Key (singular)=(das Buch) already exists.
binajmen commented 6 months ago

Problem with Remix itself: https://github.com/remix-run/remix/pull/8446