-
Notifications
You must be signed in to change notification settings - Fork 245
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
driver-adapters: Ensure error propogation works for
startTransaction
(
#4267) * driver-adapters: Ensure error propohation works for `startTransaction` `startTransaction` was not correctly wrapped when converting `Adapter` to `ErrorCapturingAdapter`. As a result, `GenericError` message was returned in case of JS error. This PR fixes the problem. Since it is hard to test those kinds of errors with real drivers, new test suite for the error propogation is introduced. It uses fake postgres adapter that throws on every call. * Add test for executeRaw
- Loading branch information
Serhii Tatarintsev
authored
Sep 21, 2023
1 parent
0872812
commit 5a6164f
Showing
6 changed files
with
546 additions
and
457 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
96 changes: 96 additions & 0 deletions
96
query-engine/driver-adapters/js/smoke-test-js/src/libquery/errors.test.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,96 @@ | ||
import { bindAdapter } from '@prisma/driver-adapter-utils' | ||
import test, { after, before, describe } from 'node:test' | ||
import { createQueryFn, initQueryEngine, throwAdapterError } from './util' | ||
import assert from 'node:assert' | ||
|
||
const fakeAdapter = bindAdapter({ | ||
flavour: 'postgres', | ||
startTransaction() { | ||
throw new Error('Error in startTransaction') | ||
}, | ||
|
||
queryRaw() { | ||
throw new Error('Error in queryRaw') | ||
}, | ||
|
||
executeRaw() { | ||
throw new Error('Error in executeRaw') | ||
}, | ||
close() { | ||
return Promise.resolve({ ok: true, value: undefined }) | ||
}, | ||
}) | ||
|
||
const engine = initQueryEngine(fakeAdapter, '../../prisma/postgres/schema.prisma') | ||
const doQuery = createQueryFn(engine, fakeAdapter) | ||
|
||
const startTransaction = async () => { | ||
const args = { isolation_level: 'Serializable', max_wait: 5000, timeout: 15000 } | ||
const res = JSON.parse(await engine.startTransaction(JSON.stringify(args), '{}')) | ||
if (res['error_code']) { | ||
throwAdapterError(res, fakeAdapter) | ||
} | ||
} | ||
|
||
describe('errors propagation', () => { | ||
before(async () => { | ||
await engine.connect('{}') | ||
}) | ||
after(async () => { | ||
await engine.disconnect('{}') | ||
}) | ||
|
||
test('works for queries', async () => { | ||
await assert.rejects( | ||
doQuery({ | ||
modelName: 'Product', | ||
action: 'findMany', | ||
query: { | ||
arguments: {}, | ||
selection: { | ||
$scalars: true, | ||
}, | ||
}, | ||
}), | ||
/Error in queryRaw/, | ||
) | ||
}) | ||
|
||
test('works for executeRaw', async () => { | ||
await assert.rejects( | ||
doQuery({ | ||
action: 'executeRaw', | ||
query: { | ||
arguments: { | ||
query: 'SELECT 1', | ||
parameters: '[]', | ||
}, | ||
selection: { | ||
$scalars: true, | ||
}, | ||
}, | ||
}), | ||
/Error in executeRaw/, | ||
) | ||
}) | ||
|
||
test('works with implicit transaction', async () => { | ||
await assert.rejects( | ||
doQuery({ | ||
modelName: 'Product', | ||
action: 'deleteMany', | ||
query: { | ||
arguments: {}, | ||
selection: { | ||
$scalars: true, | ||
}, | ||
}, | ||
}), | ||
/Error in startTransaction/, | ||
) | ||
}) | ||
|
||
test('works with explicit transaction', async () => { | ||
await assert.rejects(startTransaction(), /Error in startTransaction/) | ||
}) | ||
}) |
Oops, something went wrong.