Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Truncated call stack for PostgresError #963

Open
pesterhazy opened this issue Oct 17, 2024 · 3 comments
Open

Truncated call stack for PostgresError #963

pesterhazy opened this issue Oct 17, 2024 · 3 comments

Comments

@pesterhazy
Copy link

The call stack from PostgresError (for things like sql syntax errors or unique constraint violations) doesn't include any of my stack frames; instead it bottoms out in TCP.onStreamRead. This makes debugging database errors much more difficult. Here's an example from a test in node:test:

  Error [PostgresError]: update or delete on table "contacts" violates foreign key constraint "calls_customer_id_fkey" on table "calls"
      at ErrorResponse (/Users/paulusesterhazy/prg/telli/backend2/node_modules/postgres/cjs/src/connection.js:788:26)
      at handle (/Users/paulusesterhazy/prg/telli/backend2/node_modules/postgres/cjs/src/connection.js:474:6)
      at Socket.data (/Users/paulusesterhazy/prg/telli/backend2/node_modules/postgres/cjs/src/connection.js:315:9)
      at Socket.emit (node:events:519:28)
      at addChunk (node:internal/streams/readable:561:12)
      at readableAddChunkPushByteMode (node:internal/streams/readable:512:3)
      at Readable.push (node:internal/streams/readable:392:5)
      at TCP.onStreamRead (node:internal/stream_base_commons:189:23) {
    severity_local: 'ERROR',
    severity: 'ERROR',
    code: '23503',
    detail: 'Key (id)=(99cf2b0f-791d-41df-a911-d62ef51103cd) is still referenced from table "calls".',
    schema_name: 'public',
    table_name: 'calls',
    constraint_name: 'calls_customer_id_fkey',
    file: 'ri_triggers.c',
    line: '2478',
    routine: 'ri_ReportViolation'
  }

My understanding of the issue (which may not be accurate) is that generally v8's async stack traces should address this issue, but postgres doesn't use async/await internally for this interaction with the database so there's no coherent stack trace leading to the function call in my code.

Using postgres 3.4.4 and drizzle-orm 0.33.0.

@pesterhazy
Copy link
Author

For context, here's a similar issue in node-postgres brianc/node-postgres#2470 (comment)

@pesterhazy
Copy link
Author

I just tried switching to node-postgres, and indeed it has coherent stackframes. E.g.:

✖ getContactsGroupedByReached (7.579ms)
  error: could not determine data type of parameter $2
      at /Users/paulusesterhazy/prg/telli/backend2/node_modules/pg-pool/index.js:45:11
      at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
      at async getReached (/Users/paulusesterhazy/prg/telli/backend2/api/src/analytics.ts:122:15)
      at async getContactsGroupedByReached (/Users/paulusesterhazy/prg/telli/backend2/api/src/analytics.ts:151:20)
      at async TestContext.<anonymous> (/Users/paulusesterhazy/prg/telli/backend2/api/src/analytics.test.ts:73:18)
      at async Test.run (node:internal/test_runner/test:931:9)
      at async Test.processPendingSubtests (node:internal/test_runner/test:629:7) {

@franciscomerdot
Copy link

I got an incomplete stack trace on query failure too, I know what is wrong with my query. Why I get an incomplete stack trace, where are the async parts of it?

Error: UNDEFINED_VALUE: Undefined values are not allowed
    at handleValue (file:///Users/user/project/node_modules/postgres/src/types.js:83:20)
    at file:///Users/user/project/node_modules/postgres/src/connection.js:225:38
    at Array.forEach (<anonymous>)
    at build (file:///Users/user/project/node_modules/postgres/src/connection.js:225:25)
    at Object.execute (file:///Users/user/project/node_modules/postgres/src/connection.js:167:7)
    at go (file:///Users/user/project/node_modules/postgres/src/index.js:344:14)
    at Query.handler (file:///Users/user/project/node_modules/postgres/src/index.js:333:14)
    at Query.handle (file:///Users/user/project/node_modules/postgres/src/query.js:140:65)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

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

No branches or pull requests

4 participants
@pesterhazy @franciscomerdot and others