Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect type definitions causing confusion when trying to catch PostgresError #862

Open
michalkvasnicak opened this issue May 5, 2024 · 1 comment

Comments

@michalkvasnicak
Copy link

I noticed that when I want to catch an error and identify it using instanceof I got an error TypeError: Right-hand side of 'instanceof' is not an object. Which was caused by following code:

import { PostgresError } from 'postgres';

try {
  // await query
} catch (e) {
  if (e instanceof PostgresError) {
    // do something
  }
}

To fix that I had to use default import:

import Postgres from 'postgres';

try {
  // await query
} catch (e) {
  if (e instanceof Postgres.PostgresError) {
    // do something
  }
}

This is confusing because typescript was not able to catch the failing example as something wrong and I was able to find this error only in runtime.

@porsager
Copy link
Owner

There is no PostgresError named export so the first sample doesn't make sense and I don't know typescript so feel free to do a PR that fixes the ts issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants