Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(client): pass thru init error code on binary start (#13551)
* replication: add test to assert the error * refactor: better assertions for error name and code * refactor: combine skipDBSetup and teardown into one * fix: pass thru error code
- Loading branch information
Showing
7 changed files
with
90 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { defineMatrix } from '../_utils/defineMatrix' | ||
|
||
export default defineMatrix(() => [ | ||
[ | ||
{ | ||
provider: 'postgresql', | ||
url: 'postgresql://invalid:invalid@invalid.org:123/invalid', | ||
}, | ||
], | ||
]) |
19 changes: 19 additions & 0 deletions
19
packages/client/tests/functional/init-error/prisma/_schema.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { idForProvider } from '../../_utils/idForProvider' | ||
import testMatrix from '../_matrix' | ||
|
||
export default testMatrix.setupSchema(({ provider, url }) => { | ||
return /* Prisma */ ` | ||
generator client { | ||
provider = "prisma-client-js" | ||
} | ||
datasource db { | ||
provider = "${provider}" | ||
url = "${url}" | ||
} | ||
model User { | ||
id ${idForProvider(provider)} | ||
} | ||
` | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { PrismaClientInitializationError } from '@prisma/engine-core' | ||
|
||
import testMatrix from './_matrix' | ||
|
||
// @ts-ignore this is just for type checks | ||
declare let prisma: import('@prisma/client').PrismaClient | ||
|
||
testMatrix.setupTestSuite( | ||
() => { | ||
test('should assert that the error has the correct errorCode', async () => { | ||
expect.assertions(2) | ||
|
||
try { | ||
await prisma.$connect() | ||
} catch (error) { | ||
const e = error as PrismaClientInitializationError | ||
expect(e.constructor.name).toEqual('PrismaClientInitializationError') | ||
expect(e.errorCode).toEqual('P1001') | ||
} finally { | ||
prisma.$disconnect().catch(() => {}) | ||
} | ||
}) | ||
}, | ||
{ skipDb: true }, // So we can maually call connect for this test | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters