|
1 | 1 | /* eslint-disable @typescript-eslint/unified-signatures */
|
2 | 2 | import { Injectable, Optional } from '@nestjs/common';
|
3 |
| -import { $, Executor } from 'edgedb'; |
| 3 | +import { $, ConstraintViolationError, EdgeDBError, Executor } from 'edgedb'; |
4 | 4 | import { QueryArgs } from 'edgedb/dist/ifaces';
|
5 | 5 | import { retry, RetryOptions } from '~/common/retry';
|
| 6 | +import { jestSkipFileInExceptionSource } from '../exception'; |
6 | 7 | import { TypedEdgeQL } from './edgeql';
|
7 |
| -import { ExclusivityViolationError } from './exclusivity-violation.error'; |
| 8 | +import { enhanceConstraintError } from './errors'; |
8 | 9 | import { InlineQueryRuntimeMap } from './generated-client/inline-queries';
|
9 | 10 | import { ApplyOptions, OptionsContext } from './options.context';
|
10 | 11 | import { Client } from './reexports';
|
@@ -131,10 +132,22 @@ export class EdgeDB {
|
131 | 132 | }
|
132 | 133 | } catch (e) {
|
133 | 134 | // Ignore this call in stack trace. This puts the actual query as the first.
|
134 |
| - e.stack = e.stack!.replace(/^\s+at EdgeDB\.run.+\n/m, ''); |
| 135 | + e.stack = e.stack!.replace(/^\s+at(?: async)? EdgeDB\.run.+$\n/m, ''); |
| 136 | + |
| 137 | + // Don't present abstract repositories as the src block in jest reports |
| 138 | + // for DB execution errors. |
| 139 | + // There shouldn't be anything specific to there to be helpful. |
| 140 | + // This is a bit of a broad assumption though, so only do for jest and |
| 141 | + // keep the frame for actual use from users/devs. |
| 142 | + if (e instanceof EdgeDBError) { |
| 143 | + jestSkipFileInExceptionSource( |
| 144 | + e, |
| 145 | + /^\s+at .+src[/|\\]core[/|\\]edgedb[/|\\].+\.repository\..+$\n/gm, |
| 146 | + ); |
| 147 | + } |
135 | 148 |
|
136 |
| - if (ExclusivityViolationError.is(e)) { |
137 |
| - throw ExclusivityViolationError.cast(e); |
| 149 | + if (e instanceof ConstraintViolationError) { |
| 150 | + throw enhanceConstraintError(e); |
138 | 151 | }
|
139 | 152 | throw e;
|
140 | 153 | }
|
|
0 commit comments