Skip to content

Commit

Permalink
chore(client)!: remove NotFoundError (#25635)
Browse files Browse the repository at this point in the history
Co-authored-by: Sergey Tatarintsev <tatarintsev@prisma.io>
  • Loading branch information
aqrln and Sergey Tatarintsev authored Nov 13, 2024
1 parent 52cadd3 commit b336467
Show file tree
Hide file tree
Showing 14 changed files with 63 additions and 139 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,6 @@ Prisma.PrismaClientValidationError = () => {
throw new Error(\`PrismaClientValidationError is unable to run in this browser environment, or has been bundled for the browser (running in \${runtimeName}).
In case this error is unexpected for you, please report it in https://pris.ly/prisma-prisma-bug-report\`,
)}
Prisma.NotFoundError = () => {
const runtimeName = getRuntime().prettyName;
throw new Error(\`NotFoundError is unable to run in this browser environment, or has been bundled for the browser (running in \${runtimeName}).
In case this error is unexpected for you, please report it in https://pris.ly/prisma-prisma-bug-report\`,
)}
Prisma.Decimal = Decimal

/**
Expand Down Expand Up @@ -723,7 +718,6 @@ export namespace Prisma {
export import PrismaClientRustPanicError = runtime.PrismaClientRustPanicError
export import PrismaClientInitializationError = runtime.PrismaClientInitializationError
export import PrismaClientValidationError = runtime.PrismaClientValidationError
export import NotFoundError = runtime.NotFoundError

/**
* Re-export of sql-template-tag
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,6 @@ Prisma.PrismaClientValidationError = () => {
throw new Error(\`PrismaClientValidationError is unable to run in this browser environment, or has been bundled for the browser (running in \${runtimeName}).
In case this error is unexpected for you, please report it in https://pris.ly/prisma-prisma-bug-report\`,
)}
Prisma.NotFoundError = () => {
const runtimeName = getRuntime().prettyName;
throw new Error(\`NotFoundError is unable to run in this browser environment, or has been bundled for the browser (running in \${runtimeName}).
In case this error is unexpected for you, please report it in https://pris.ly/prisma-prisma-bug-report\`,
)}
Prisma.Decimal = Decimal

/**
Expand Down Expand Up @@ -723,7 +718,6 @@ export namespace Prisma {
export import PrismaClientRustPanicError = runtime.PrismaClientRustPanicError
export import PrismaClientInitializationError = runtime.PrismaClientInitializationError
export import PrismaClientValidationError = runtime.PrismaClientValidationError
export import NotFoundError = runtime.NotFoundError

/**
* Re-export of sql-template-tag
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,6 @@ Prisma.PrismaClientValidationError = () => {
throw new Error(\`PrismaClientValidationError is unable to run in this browser environment, or has been bundled for the browser (running in \${runtimeName}).
In case this error is unexpected for you, please report it in https://pris.ly/prisma-prisma-bug-report\`,
)}
Prisma.NotFoundError = () => {
const runtimeName = getRuntime().prettyName;
throw new Error(\`NotFoundError is unable to run in this browser environment, or has been bundled for the browser (running in \${runtimeName}).
In case this error is unexpected for you, please report it in https://pris.ly/prisma-prisma-bug-report\`,
)}
Prisma.Decimal = Decimal

/**
Expand Down Expand Up @@ -752,7 +747,6 @@ export namespace Prisma {
export import PrismaClientRustPanicError = runtime.PrismaClientRustPanicError
export import PrismaClientInitializationError = runtime.PrismaClientInitializationError
export import PrismaClientValidationError = runtime.PrismaClientValidationError
export import NotFoundError = runtime.NotFoundError

/**
* Re-export of sql-template-tag
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,6 @@ Prisma.PrismaClientValidationError = () => {
throw new Error(\`PrismaClientValidationError is unable to run in this browser environment, or has been bundled for the browser (running in \${runtimeName}).
In case this error is unexpected for you, please report it in https://pris.ly/prisma-prisma-bug-report\`,
)}
Prisma.NotFoundError = () => {
const runtimeName = getRuntime().prettyName;
throw new Error(\`NotFoundError is unable to run in this browser environment, or has been bundled for the browser (running in \${runtimeName}).
In case this error is unexpected for you, please report it in https://pris.ly/prisma-prisma-bug-report\`,
)}
Prisma.Decimal = Decimal

/**
Expand Down Expand Up @@ -752,7 +747,6 @@ export namespace Prisma {
export import PrismaClientRustPanicError = runtime.PrismaClientRustPanicError
export import PrismaClientInitializationError = runtime.PrismaClientInitializationError
export import PrismaClientValidationError = runtime.PrismaClientValidationError
export import NotFoundError = runtime.NotFoundError

/**
* Re-export of sql-template-tag
Expand Down
4 changes: 0 additions & 4 deletions packages/client/src/generation/TSClient/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import {
PrismaClientRustPanicError,
PrismaClientInitializationError,
PrismaClientValidationError,
NotFoundError,
getPrismaClient,
sqltag,
empty,
Expand Down Expand Up @@ -56,7 +55,6 @@ const {
PrismaClientRustPanicError,
PrismaClientInitializationError,
PrismaClientValidationError,
NotFoundError,
getPrismaClient,
sqltag,
empty,
Expand Down Expand Up @@ -95,7 +93,6 @@ Prisma.PrismaClientUnknownRequestError = ${notSupportOnBrowser('PrismaClientUnkn
Prisma.PrismaClientRustPanicError = ${notSupportOnBrowser('PrismaClientRustPanicError', browser)}
Prisma.PrismaClientInitializationError = ${notSupportOnBrowser('PrismaClientInitializationError', browser)}
Prisma.PrismaClientValidationError = ${notSupportOnBrowser('PrismaClientValidationError', browser)}
Prisma.NotFoundError = ${notSupportOnBrowser('NotFoundError', browser)}
Prisma.Decimal = Decimal
/**
Expand Down Expand Up @@ -173,7 +170,6 @@ export import PrismaClientUnknownRequestError = runtime.PrismaClientUnknownReque
export import PrismaClientRustPanicError = runtime.PrismaClientRustPanicError
export import PrismaClientInitializationError = runtime.PrismaClientInitializationError
export import PrismaClientValidationError = runtime.PrismaClientValidationError
export import NotFoundError = runtime.NotFoundError
/**
* Re-export of sql-template-tag
Expand Down
7 changes: 0 additions & 7 deletions packages/client/src/runtime/RequestHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import {
import { QueryEngineResult } from './core/engines/common/types/QueryEngine'
import { throwValidationException } from './core/errorRendering/throwValidationException'
import { hasBatchIndex } from './core/errors/ErrorWithBatchIndex'
import { NotFoundError } from './core/errors/NotFoundError'
import { createApplyBatchExtensionsFunction } from './core/extensions/applyQueryExtensions'
import { MergedExtensionsList } from './core/extensions/MergedExtensionsList'
import { deserializeJsonResponse } from './core/jsonProtocol/deserializeJsonResponse'
Expand Down Expand Up @@ -199,12 +198,6 @@ export class RequestHandler {
throw error
}

if (error instanceof NotFoundError) {
// TODO: This is a workaround to keep backwards compatibility with clients
// consuming NotFoundError
throw error
}

if (error instanceof PrismaClientKnownRequestError && isValidationError(error)) {
const validationError = convertValidationError(error.meta as EngineValidationError)
throwValidationException({
Expand Down
17 changes: 0 additions & 17 deletions packages/client/src/runtime/core/errors/NotFoundError.ts

This file was deleted.

6 changes: 1 addition & 5 deletions packages/client/src/runtime/core/model/applyModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import type { UserArgs } from '../request/UserArgs'
import { applyAggregates } from './applyAggregates'
import { applyFieldsProxy } from './applyFieldsProxy'
import { applyFluent } from './applyFluent'
import { adaptErrors } from './applyOrThrowErrorAdapter'
import { dmmfToJSModelName } from './utils/dmmfToJSModelName'

export type ModelAction = (
Expand Down Expand Up @@ -74,9 +73,6 @@ function modelActionsLayer(client: Client, dmmfModelName: string): CompositeProx
getPropertyValue(key) {
const dmmfActionName = key as DMMF.ModelAction

let requestFn = (params: InternalRequestParams) => client._request(params)
requestFn = adaptErrors(dmmfActionName, dmmfModelName, client._clientVersion, requestFn)

// we return a function as the model action that we want to expose
// it takes user args and executes the request in a Prisma Promise
const action = (paramOverrides: O.Optional<InternalRequestParams>) => (userArgs?: UserArgs) => {
Expand All @@ -103,7 +99,7 @@ function modelActionsLayer(client: Client, dmmfModelName: string): CompositeProx
callsite: callSite,
}

return requestFn({ ...params, ...paramOverrides })
return client._request({ ...params, ...paramOverrides })
})
}

Expand Down
64 changes: 0 additions & 64 deletions packages/client/src/runtime/core/model/applyOrThrowErrorAdapter.ts

This file was deleted.

1 change: 0 additions & 1 deletion packages/client/src/runtime/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ export { Public }

export { type BaseDMMF, type DMMF } from '../generation/dmmf-types'
export { type JsonBatchQuery, type JsonQuery } from './core/engines'
export { NotFoundError } from './core/errors/NotFoundError'
export { PrismaClientInitializationError } from './core/errors/PrismaClientInitializationError'
export { PrismaClientKnownRequestError } from './core/errors/PrismaClientKnownRequestError'
export { PrismaClientRustPanicError } from './core/errors/PrismaClientRustPanicError'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,6 @@ describe('import from browser bundle should error', () => {
`PrismaClientValidationError is unable to run in this browser environment, or has been bundled for the browser`,
)
})
test('Prisma.NotFoundError', () => {
expect(Prisma.NotFoundError).toThrow(
`NotFoundError is unable to run in this browser environment, or has been bundled for the browser`,
)
})

test('Prisma.getExtensionContext', () => {
expect(Prisma.getExtensionContext).toThrow(
Expand Down
32 changes: 27 additions & 5 deletions packages/client/tests/functional/methods/findFirstOrThrow/tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ import { expectTypeOf } from 'expect-type'

import testMatrix from './_matrix'
// @ts-ignore
import type { Prisma as PrismaNamespace, PrismaClient } from './node_modules/@prisma/client'
import type { PrismaClient } from './node_modules/@prisma/client'

declare let prisma: PrismaClient
declare let Prisma: typeof PrismaNamespace

const existingEmail = faker.internet.email()
const nonExistingEmail = faker.internet.email()
Expand All @@ -25,7 +24,10 @@ testMatrix.setupTestSuite((_suiteConfig, _suiteMeta, clientMeta) => {
test('throws if record was not found', async () => {
const record = prisma.user.findFirstOrThrow({ where: { email: nonExistingEmail } })

await expect(record).rejects.toMatchObject(new Prisma.NotFoundError('No User found', '0.0.0'))
await expect(record).rejects.toMatchObject({
name: 'PrismaClientKnownRequestError',
code: 'P2025',
})
})

// batch transaction needs to be implemented. Unskip once https://github.com/prisma/team-orm/issues/997 is done
Expand All @@ -38,7 +40,17 @@ testMatrix.setupTestSuite((_suiteConfig, _suiteMeta, clientMeta) => {
prisma.user.findFirstOrThrow({ where: { email: nonExistingEmail } }),
])

await expect(result).rejects.toThrowErrorMatchingInlineSnapshot(`"No User found"`)
await expect(result).rejects.toThrowErrorMatchingInlineSnapshot(`
"
Invalid \`prisma.user.findFirstOrThrow()\` invocation in
/client/tests/functional/methods/findFirstOrThrow/tests.ts:0:0
37 const newEmail = faker.internet.email()
38 const result = prisma.$transaction([
39 prisma.user.create({ data: { email: newEmail } }),
→ 40 prisma.user.findFirstOrThrow(
An operation failed because it depends on one or more records that were required but not found. Expected a record, found none."
`)

const record = await prisma.user.findFirst({ where: { email: newEmail } })
expect(record).toBeNull()
Expand All @@ -54,7 +66,17 @@ testMatrix.setupTestSuite((_suiteConfig, _suiteMeta, clientMeta) => {
await prisma.user.findFirstOrThrow({ where: { email: nonExistingEmail } })
})

await expect(result).rejects.toThrowErrorMatchingInlineSnapshot(`"No User found"`)
await expect(result).rejects.toThrowErrorMatchingInlineSnapshot(`
"
Invalid \`prisma.user.findFirstOrThrow()\` invocation in
/client/tests/functional/methods/findFirstOrThrow/tests.ts:0:0
63 const newEmail = faker.internet.email()
64 const result = prisma.$transaction(async (prisma) => {
65 await prisma.user.create({ data: { email: newEmail } })
→ 66 await prisma.user.findFirstOrThrow(
An operation failed because it depends on one or more records that were required but not found. Expected a record, found none."
`)

const record = await prisma.user.findFirst({ where: { email: newEmail } })
expect(record).toBeNull()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ import { expectTypeOf } from 'expect-type'

import testMatrix from './_matrix'
// @ts-ignore
import type { Prisma as PrismaNamespace, PrismaClient } from './node_modules/@prisma/client'
import type { PrismaClient } from './node_modules/@prisma/client'

declare let prisma: PrismaClient
declare let Prisma: typeof PrismaNamespace

const existingEmail = faker.internet.email()
const nonExistingEmail = faker.internet.email()
Expand All @@ -24,7 +23,10 @@ testMatrix.setupTestSuite((_suiteConfig, _suiteMeta, clientMeta) => {

test('throws if record was not found', async () => {
const record = prisma.user.findUniqueOrThrow({ where: { email: nonExistingEmail } })
await expect(record).rejects.toMatchObject(new Prisma.NotFoundError('No User found', '0.0.0'))
await expect(record).rejects.toMatchObject({
name: 'PrismaClientKnownRequestError',
code: 'P2025',
})
})

// batch transaction needs to be implemented. Unskip once https://github.com/prisma/team-orm/issues/997 is done
Expand All @@ -37,7 +39,17 @@ testMatrix.setupTestSuite((_suiteConfig, _suiteMeta, clientMeta) => {
prisma.user.findUniqueOrThrow({ where: { email: nonExistingEmail } }),
])

await expect(result).rejects.toThrowErrorMatchingInlineSnapshot(`"No User found"`)
await expect(result).rejects.toThrowErrorMatchingInlineSnapshot(`
"
Invalid \`prisma.user.findUniqueOrThrow()\` invocation in
/client/tests/functional/methods/findUniqueOrThrow/tests.ts:0:0
36 const newEmail = faker.internet.email()
37 const result = prisma.$transaction([
38 prisma.user.create({ data: { email: newEmail } }),
→ 39 prisma.user.findUniqueOrThrow(
An operation failed because it depends on one or more records that were required but not found. Expected a record, found none."
`)

const record = await prisma.user.findUnique({ where: { email: newEmail } })
expect(record).toBeNull()
Expand All @@ -53,7 +65,17 @@ testMatrix.setupTestSuite((_suiteConfig, _suiteMeta, clientMeta) => {
await prisma.user.findUniqueOrThrow({ where: { email: nonExistingEmail } })
})

await expect(result).rejects.toThrowErrorMatchingInlineSnapshot(`"No User found"`)
await expect(result).rejects.toThrowErrorMatchingInlineSnapshot(`
"
Invalid \`prisma.user.findUniqueOrThrow()\` invocation in
/client/tests/functional/methods/findUniqueOrThrow/tests.ts:0:0
62 const newEmail = faker.internet.email()
63 const result = prisma.$transaction(async (prisma) => {
64 await prisma.user.create({ data: { email: newEmail } })
→ 65 await prisma.user.findUniqueOrThrow(
An operation failed because it depends on one or more records that were required but not found. Expected a record, found none."
`)

const record = await prisma.user.findUnique({ where: { email: newEmail } })
expect(record).toBeNull()
Expand Down
Loading

0 comments on commit b336467

Please sign in to comment.