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

PrismaClientInitializationError is missing errorCode property #18813

Open
shiba-sama opened this issue Apr 18, 2023 · 3 comments
Open

PrismaClientInitializationError is missing errorCode property #18813

shiba-sama opened this issue Apr 18, 2023 · 3 comments
Labels
bug/2-confirmed Bug has been reproduced and confirmed. kind/regression A reported bug in functionality that used to work before. team/client Issue for team Client. topic: error

Comments

@shiba-sama
Copy link

shiba-sama commented Apr 18, 2023

Bug description

  • According to the docs, the PrismaClientInitializationError type should have an errorCode property but I'm seeing undefined for a range of errors which have this type.
  • Currently the workaround is to match on the exact error message string, but I assume that's not something the Prisma team wants.

How to reproduce

  1. Create a vanilla Prisma project and connect it to a DB.
  2. Produce various connection errors like wrong username or password or disconnect your DB.
  3. Try to make a query from the Prisma client and catch the error.
  4. Inspect whether the error is an instance of PrismaClientInitializationError.
  5. Inspect the errorCode property and see if it's undefined.

Expected behavior

Would be preferable if Prisma docs had a list of error codes and the associated error.

Prisma information

This is a connection error issue which can be replicated on any toy schema.

Environment & setup

  • MacOS & Ubuntu
  • PostgreSQL 15
  • Node 19

Prisma Version

4.13
@shiba-sama shiba-sama added the kind/bug A reported bug. label Apr 18, 2023
@Weakky Weakky added the team/client Issue for team Client. label Apr 21, 2023
@Weakky
Copy link
Member

Weakky commented Apr 21, 2023

Hey @shiba-sama, thanks for reporting 🙏.

Internal note: It looks like a regression of #10229. Thing is, we already have a regression test for it, which seems to be testing exactly that.

@Weakky Weakky added kind/regression A reported bug in functionality that used to work before. bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. topic: error labels Apr 21, 2023
@AndrewSouthpaw
Copy link
Contributor

Thanks for the investigation so far, @Weakky! Just wanted to signal boost this, we ran into it as well. We can implement the workaround for now.

If we were to rely on the errorCode though and it had another regression, that could lead to production outages, so hopefully the mystery of the regression test not catching it can be resolved.

@SevInf
Copy link
Contributor

SevInf commented Aug 18, 2023

I can confirm the issue on 5.1.1:

async function main() {
  const prisma = new PrismaClient({
    datasources: {
      db: { url: 'postgres://invalid:invalid@localhost:5432/invalid' },
    },
  })

  try {
    await prisma.user.findMany()
  } catch (error) {
    console.log(error.errorCode)
  }
}

Logs undefined

Important node: it does not happen with explicit $connect call, only with implicit one done by findMany. That explains while test mentioned above did not catch it.

Unitl it fixed, the workeraound is to call prisma.$connect() some time before you execute your first query.

@SevInf SevInf added bug/2-confirmed Bug has been reproduced and confirmed. and removed bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. labels Aug 18, 2023
@janpio janpio removed the kind/bug A reported bug. label Aug 22, 2023
@apolanc apolanc added bug/0-unknown Bug is new, does not have information for reproduction or reproduction could not be confirmed. bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. and removed bug/0-unknown Bug is new, does not have information for reproduction or reproduction could not be confirmed. bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. labels Jan 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug/2-confirmed Bug has been reproduced and confirmed. kind/regression A reported bug in functionality that used to work before. team/client Issue for team Client. topic: error
Projects
None yet
Development

No branches or pull requests

6 participants