porsager / postgres

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

TypeError: Cannot read properties of undefined (reading 'replace') #923

Open alexgleason opened 3 months ago

alexgleason commented 3 months ago

I'm getting some kind of error, but the error handler itself has an error, so I'm not sure what the error is. :smiley:

error: Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'replace')
      stack: { value: err.stack + query.origin.replace(/.*\n/, '\n'), enumerable: options.debug },
                                               ^
    at queryError (https://deno.land/x/postgresjs@v3.4.4/src/connection.js:392:48)
    at errored (https://deno.land/x/postgresjs@v3.4.4/src/connection.js:387:17)
    at error (https://deno.land/x/postgresjs@v3.4.4/src/connection.js:379:5)
    at https://deno.land/x/postgresjs@v3.4.4/polyfills.js:138:30
    at Array.forEach (<anonymous>)
    at call (https://deno.land/x/postgresjs@v3.4.4/polyfills.js:138:16)
    at error (https://deno.land/x/postgresjs@v3.4.4/polyfills.js:131:5)
    at eventLoopTick (ext:core/01_core.js:168:7)
alexgleason commented 3 months ago

So I edited the code manually and logged it. err is:

InvalidData: invalid peer certificate: UnknownIssuer
    at async TlsConn.read (ext:deno_net/01_net.js:150:15)
    at async success (https://raw.githubusercontent.com/alexgleason/postgres.js/51ac395234089d5b7806c471830a1a472958fb06/deno/polyfills.js:97:56) {
  name: "InvalidData"
}

And the value of query is... true ???

EDIT: It's because query is being set to true here: https://github.com/porsager/postgres/blob/f58cd4f3affd3e8ce8f53e42799672d86cd2c70b/src/connection.js#L112

marbemac commented 2 months ago

Running into this as well

patrickReiis commented 2 months ago

I'm also having this problem

tilemanrenovations commented 2 months ago

How long has this been happening?

dhardtke commented 1 week ago

We are also seeing this error in our projects:

TypeError: Cannot read properties of undefined (reading 'replace')
    at queryError (/usr/src/app/node_modules/postgres/cjs/src/connection.js:389:48)
    at errored (/usr/src/app/node_modules/postgres/cjs/src/connection.js:383:14)
    at TLSSocket.data (/usr/src/app/node_modules/postgres/cjs/src/connection.js:318:9)
    at TLSSocket.emit (node:events:519:28)
    at addChunk (node:internal/streams/readable:559:12)
    at readableAddChunkPushByteMode (node:internal/streams/readable:510:3)
    at Readable.push (node:internal/streams/readable:390:5)
    at TLSWrap.onStreamRead (node:internal/stream_base_commons:191:23)

I am not convinced it is an issue with the initial query since /usr/src/app/node_modules/postgres/cjs/src/connection.js:383:14 points to https://github.com/porsager/postgres/blob/a2c7de12b3bfc6809051d94ba6115150f80678e3/src/connection.js#L383

It is very problematic that we don't see the actual error. It does not happen on startup but when our NodeJS backend is under high load.