Skip to content

Incorrect constructor parameter types for class PostgresError #703

Open
@jaydenseric

Description

@jaydenseric

According to the types, to construct a new PostgresError the first argument is a message string:

Screenshot 2023-10-20 at 10 14 32 am

With this code:

import postgres from "postgres";

const error = new postgres.PostgresError("Error message.");

console.log(Object.entries(error));

What actually logs is:

[
  [ '0', 'E' ],
  [ '1', 'r' ],
  [ '2', 'r' ],
  [ '3', 'o' ],
  [ '4', 'r' ],
  [ '5', ' ' ],
  [ '6', 'm' ],
  [ '7', 'e' ],
  [ '8', 's' ],
  [ '9', 's' ],
  [ '10', 'a' ],
  [ '11', 'g' ],
  [ '12', 'e' ],
  [ '13', '.' ],
  [ 'name', 'PostgresError' ]
]

That's because actually the first argument it seems is supposed to be an Error instance:

export class PostgresError extends Error {
constructor(x) {
super(x.message)
this.name = this.constructor.name
Object.assign(this, x)
}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions