Currently, I am in the process of debugging some tests that were written with jest using typescript and it's causing quite a headache.
Whenever a test or tested class runs Postgres SQL and encounters an error in the query, the stack trace provided is not helpful. For example, you might see something like this:
Error: invalid input syntax for type integer: ""0""
at Parser.parseErrorMessage (/Users/sklivvz/src/xxx/node_modules/pg-protocol/src/parser.ts:369:69)
at Parser.handlePacket (/Users/sklivvz/src/xxx/node_modules/pg-protocol/src/parser.ts:188:21)
at Parser.parse (/Users/sklivvz/src/xxx/node_modules/pg-protocol/src/parser.ts:103:30)
at Socket.<anonymous> (/Users/sklivvz/src/xxx/node_modules/pg-protocol/src/index.ts:7:48)
at Socket.emit (node:events:365:28)
at addChunk (node:internal/streams/readable:314:12)
at readableAddChunk (node:internal/streams/readable:289:9)
at Socket.Readable.push (node:internal/streams/readable:228:10)
at TCP.onStreamRead (node:internal/stream_base_commons:190:23)
The line mentioning the "error" is useful, but the stack trace only indicates that the error originated from the pg-protocol driver. It would be more beneficial to pinpoint exactly which part of my code caused the error.
I have a strong feeling, around 82.7%, that this issue stems from PG's query
being asynchronous.
Debugging by stepping through or resorting to console.log
every error is incredibly time-consuming when simply showing the correct call stack could provide a much clearer picture.
Has anyone discovered a developer-friendly solution to this problem?