-
Notifications
You must be signed in to change notification settings - Fork 11
Open
Description
When running a query using a cursor and backpressure, I've seen this error sporadically (multiple times) which crashes all of NodeRed.
17 Jul 00:22:13 - [error] TypeError: Cannot read properties of undefined (reading 'command')
at cursorcallback (/data/node_modules/node-red-contrib-postgresql/postgresql.js:253:27)
at Immediate.<anonymous> (/data/node_modules/pg-cursor/index.js:249:26)
at process.processImmediate (node:internal/timers:483:21)
It seems to refer to this line:
node-red-contrib-postgresql/postgresql.js
Lines 255 to 258 in 9eb8cfe
pgsql: { | |
command: result.command, | |
rowCount: result.rowCount, | |
}, |
and this pg-cursor line setImmediate(() => cb(null, []))
So it looks like in some cases, result may be undefined.
The fix seems to be:
pgsql: result ? {
command: result.command,
rowCount: result.rowCount,
} : undefined,
or if you prefer
pgsql: {
command: result?.command,
rowCount: result?.rowCount,
},
It may also be worthwhile to wrap the whole function in a try/except block for good measure so that the node is safer from total nodered crashes.
Alkarex
Metadata
Metadata
Assignees
Labels
No labels