Skip to content

Uncaught pg-cursor exception: Cannot read properties of undefined (reading 'command')Β #114

@beasteers

Description

@beasteers

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:

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions