Skip to content

Database Error instances should be instances of the builtin Error class #50

Closed
@homme

Description

@homme

Hi,

Firstly, thanks for node-postgres - a lot of our projects use Postgres and node-postgres provides a great bridge to Node.

The database errors I've come across in node-postgres (either returned in callbacks or emitted via 'error' events) are all object literals and not Error instances. This means they don't have stack information and can't be handled by default software error handlers. These software handlers include the default node handler and the Express default handler. The former produces an "Uncaught, unspecified 'error' event." (see issue #41) and the latter just emits an 'undefined' error rather than producing a nice stack trace.

It would be great to have node-postgres emit database errors that are at instances of (or subclasses of) the builtin Error class, such that the following holds true:

client.query(
    'BAD SQL: RETURN AN ERROR',
    function (err, result) {
        assert.ok(err instanceof Error);
    }
);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions