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

TypeError: Attempting to change value of a readonly property. #734

Closed xlc closed 1 month ago

xlc commented 8 months ago

Getting those error

error: write CONNECT_TIMEOUT xxxxx.eu-west-1.rds.amazonaws.com:5432
 code: "CONNECT_TIMEOUT"

      at connection (/home/bun/app/node_modules/postgres/src/errors.js:26:2)
      at connectTimedOut (/home/bun/app/node_modules/postgres/src/connection.js:257:12)
      at done (/home/bun/app/node_modules/postgres/src/connection.js:1035:4)
383 |     query && queryError(query, err)
384 |     initial && (queryError(initial, err), initial = null)
385 |   }
386 | 
387 |   function queryError(query, err) {
388 |     Object.defineProperties(err, {
        ^
TypeError: Attempting to change value of a readonly property.
      at queryError (/home/bun/app/node_modules/postgres/src/connection.js:388:4)
      at errored (/home/bun/app/node_modules/postgres/src/connection.js:384:16)
      at connectTimedOut (/home/bun/app/node_modules/postgres/src/connection.js:257:4)
      at done (/home/bun/app/node_modules/postgres/src/connection.js:1035:4)

Using version 3.4.3 and bun v1.0.13

The write timeout could be my app doing something wrong but I don't expect TypeError

paoliniluis commented 6 months ago

you have a timeout there, the "Attempting to change value of a readonly property" seems like a complimentary thing on the stack trace

xlc commented 6 months ago

I know. But a timeout shouldn’t causing TypeError.

tgrushka commented 5 months ago

Yep, same problem. It's in the library.

TypeError: Attempting to change value of a readonly property.
      at queryError (/app/node_modules/postgres/src/connection.js:388:5)
      at errored (/app/node_modules/postgres/src/connection.js:384:17)
      at data (/app/node_modules/postgres/src/connection.js:318:9)
      at addChunk (node:stream:1940:43)
      at readableAddChunk (node:stream:1894:59)
      at data (node:net:52:17)
27 |   return error
28 | }
29 | 
30 | function postgres(x) {
31 |   const error = new PostgresError(x)
32 |   Error.captureStackTrace(error, postgres)
             ^
PostgresError: query_wait_timeout
 code: "08P01"

Your problem is here:

  function queryError(query, err) {
    /// `err` is undefined here for some reason.
    /// Should handle null/undefined case so that the error handler *itself* doesn't throw an undefined error.
    /// Line 388:
    Object.defineProperties(err, {
      stack: { value: err.stack + query.origin.replace(/.*\n/, '\n'), enumerable: options.debug },
      query: { value: query.string, enumerable: options.debug },
      parameters: { value: query.parameters, enumerable: options.debug },
      args: { value: query.args, enumerable: options.debug },
      types: { value: query.statement && query.statement.types, enumerable: options.debug }
    })
    query.reject(err)
  }
porsager commented 1 month ago

It works in node, so you should file an issue in bun about not being able to override properties on an Error instance.