forked from zenstackhq/zenstack
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: improve stacktrace of errors generated by proxied Prisma methods (…
- Loading branch information
Showing
2 changed files
with
105 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { loadSchema } from '@zenstackhq/testtools'; | ||
import path from 'path'; | ||
|
||
describe('Stack trace tests', () => { | ||
let origDir: string; | ||
|
||
beforeAll(async () => { | ||
origDir = path.resolve('.'); | ||
}); | ||
|
||
afterEach(() => { | ||
process.chdir(origDir); | ||
}); | ||
|
||
it('stack trace', async () => { | ||
const { withPolicy } = await loadSchema( | ||
` | ||
model Model { | ||
id String @id @default(uuid()) | ||
} | ||
` | ||
); | ||
|
||
const db = withPolicy(); | ||
let error: Error | undefined = undefined; | ||
|
||
try { | ||
await db.model.create({ data: {} }); | ||
} catch (err) { | ||
error = err as Error; | ||
} | ||
|
||
expect(error?.stack).toContain( | ||
"Error calling enhanced Prisma method `create`: denied by policy: model entities failed 'create' check" | ||
); | ||
expect(error?.stack).toContain(`misc/stacktrace.test.ts`); | ||
expect((error as any).internalStack).toBeTruthy(); | ||
}); | ||
}); |