【发布时间】:2020-11-14 15:24:00
【问题描述】:
我有一个应用程序,它使用出色的 pg-promise 库查询 PostgreSQL 数据库。
在查询语法包含错误的情况下,有没有办法获得友好的堆栈跟踪?通过 Node 配置或 pg-promise 配置。
- 在查询错误中抛出的
UnhandledPromiseRejectionWarning并未指明应用程序在其中进行查询的源代码 - 我不想用单独的尝试捕获来装饰所有查询,只是为了查明无效查询
这是一个无用的堆栈跟踪示例:
(node:53357) UnhandledPromiseRejectionWarning: error: there is no parameter $1
at Parser.parseErrorMessage (/Users/moo/code/myapp/node_modules/pg-protocol/dist/parser.js:278:15)
at Parser.handlePacket (/Users/moo/code/myapp/node_modules/pg-protocol/dist/parser.js:126:29)
at Parser.parse (/Users/moo/code/myapp/node_modules/pg-protocol/dist/parser.js:39:38)
at Socket.<anonymous> (/Users/moo/code/myapp/node_modules/pg-protocol/dist/index.js:8:42)
at Socket.emit (events.js:314:20)
at addChunk (_stream_readable.js:303:12)
at readableAddChunk (_stream_readable.js:279:9)
at Socket.Readable.push (_stream_readable.js:218:10)
at TCP.onStreamRead (internal/stream_base_commons.js:188:23)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:53357) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
(node:53357) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
在此堆栈跟踪中没有指示查询是在哪里进行的,这使得查明错误变得困难。此外,添加 node --trace-warnings 不会向堆栈跟踪添加更多有用的上下文。
或者,是否有任何其他适用于 Node 的 PostgreSQL 连接器库具有更多错误跟踪功能?
节点 v14。
【问题讨论】:
标签: node.js postgresql pg-promise