Unable to catch error in query
See original GitHub issueBug description
This is my query:
try {
return await prisma.user.findUnique({
where: {
id: 'HQNsa'
}
})
} catch(e) { // this does not catch the error
console.log(e);
}
The id
column is of type @db.Uuid
in Postgres so obviously this request will fail because it is not a valid UUID.
This is the error:
C:\Users\...\node_modules\@prisma\client\runtime\index.js:45578
throw new PrismaClientKnownRequestError(message, e.code, this.client._clientVersion, e.meta);
^
PrismaClientKnownRequestError:
Invalid `prisma.user.findUnique()` invocation:
Inconsistent column data: Error creating UUID, invalid length: expected one of [36, 32], found 5
at Object.request (C:\Users\...\node_modules\@prisma\client\runtime\index.js:45578:15) {
code: 'P2023',
clientVersion: '3.12.0',
meta: {
message: 'Error creating UUID, invalid length: expected one of [36, 32], found 5'
}
}
My problem is not that the error gets thrown. I completely understand what the problem is with my query. However, my problem is that my try / catch block is unable to catch it. I therefore think that the error gets thrown in another scope.
Is this intended? I tried many things (e.g. also wrapping the PrismaClient instantiation into a try / catch block or not putting await in front of the query) but nothing seems to work.
I know that I could check whether my input string is a UUID before querying but I would like to just catch the error.
How to reproduce
- Create a Prisma schema with a postgres datasource and create a simple model where the
@id
column is of type@db.Uuid
. - Push the schema to the DB
- Try running the following query (change model accordingly)
prisma.user.findUnique({
where: {
id: 'HQNsa'
}
})
- Try to catch the error that occurs to prevent the server from crashing. I wasn’t able to.
Expected behavior
I would like to be able to catch errors where they occur, not have them crash my server without me being able to catch them.
Prisma information
E.g.:
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
generator client {
provider = "prisma-client-js"
}
model User {
id String @id @db.Uuid
name String
}
Environment & setup
- OS: Windows 10
- Database: Postgres
- Node.js version: 16.14.2
Prisma Version
prisma : 3.12.0
@prisma/client : 3.12.0
Current platform : windows
Query Engine (Node-API) : libquery-engine 22b822189f46ef0dc5c5b503368d1bee01213980 (at node_modules\@prisma\engines\query_engine-windows.dll.node)
Migration Engine : migration-engine-cli 22b822189f46ef0dc5c5b503368d1bee01213980 (at node_modules\@prisma\engines\migration-engine-windows.exe)
Introspection Engine : introspection-core 22b822189f46ef0dc5c5b503368d1bee01213980 (at node_modules\@prisma\engines\introspection-engine-windows.exe)
Format Binary : prisma-fmt 22b822189f46ef0dc5c5b503368d1bee01213980 (at node_modules\@prisma\engines\prisma-fmt-windows.exe)
Default Engines Hash : 22b822189f46ef0dc5c5b503368d1bee01213980
Studio : 0.459.0
Issue Analytics
- State:
- Created a year ago
- Comments:9 (3 by maintainers)
Top GitHub Comments
@janpio yes I confirm that !
Yes, that is exactly what I am doing. I added the
await
and it works now so I am closing this. Thanks guys!