Repository navigation
feat(client): Export NotFoundError in Prisma namespace - #14076
Conversation
aqrln
left a comment
There was a problem hiding this comment.
On the second look, I think it will fail at run time because it's still missing in the JS bundle — you have only added it to the TS typings and the browser bundle stub, as far as I can tell.
|
Hi @aqrln, I have tested the runtime by copy/pasting the basic-sqlite reproduction and replacing the script.ts with the following code: import { PrismaClient, Prisma } from '.prisma/client'
async function main() {
const prisma = new PrismaClient()
try {
const user = await prisma.user.findUniqueOrThrow({
where: { email: '[email protected] ' },
})
console.log({ user })
} catch (e: unknown) {
if (e instanceof Prisma.NotFoundError) {
console.error('The error is an instance of Prisma.NotFoundError')
} else {
console.error('Unknown error')
}
}
console.log('------------')
try {
throw new Prisma.NotFoundError('message')
} catch (e: unknown) {
console.error(e)
}
}
void main().catch((e) => {
console.log(e.message)
process.exit(1)
})I have tested it using the following commands: ❯ rm -rf node_modules && pnpm i && pnpx prisma generate && pnpx ts-node index.ts
Scope: all 2 workspace projects
.. | Progress: resolved 16, reused 16, downloaded 0, added 0, done
dependencies:
+ @prisma/client 0.0.0 <- ../../packages/client
devDependencies:
+ @types/node 17.0.21
+ prisma 0.0.0 <- ../../packages/cli
+ ts-node 10.8.1
+ typescript 4.7.4
Prisma schema loaded from prisma/schema.prisma
✔ Generated Prisma Client (0.0.0 | library) to ./node_modules/.prisma/client in 152ms
You can now start using Prisma Client in your code. Reference: https://pris.ly/d/client
\```
import { PrismaClient } from './node_modules/.prisma/client'
const prisma = new PrismaClient()
\```
The error is an instance of Prisma.NotFoundError
------------
NotFoundError: message
at main (/private/tmp/prisma/reproductions/not-found-error/index.ts:23:11)In my eyes, it seems to work, but I may be missing something? Thanks |
|
@lodi-g sorry, I haven't had time to take another look yet. I'll get back to you tomorrow. In the meantime, would you mind adding small tests for this in And thank you once again for your contribution, we'll get it merged soon! |
2273daf to
afabab9
Compare
Sorry, I was confused by the diff in the snapshots in the I've changed some tests to also check if the thrown error is an instance of |
|
Thanks @aqrln! |
|
No worries! Sorry that it was confusing, this indeed is not documented in the testing guide, as far as I can see. We should definitely improve it! FWIW, it would be, for example, |
|
Great timing, was just reaching for Thank you all! |
|
@solomonhawk yes, it's going to be released in It's also available in |
The
NotFoundErrorused byfindXOrThrowis not available in the Prisma namespace, which makes it hard to perform error verification.This PR adds the necessary code to export the
NotFoundError, both the type declaration and the runtime code.Ref: #12159 (comment)