@@ -3,6 +3,7 @@ import { Injectable } from '@nestjs/common';
3
3
import { $ , Executor } from 'edgedb' ;
4
4
import { retry , RetryOptions } from '~/common/retry' ;
5
5
import { TypedEdgeQL } from './edgeql' ;
6
+ import { ExclusivityViolationError } from './exclusivity-violation.error' ;
6
7
import { InlineQueryCardinalityMap } from './generated-client/inline-queries' ;
7
8
import { OptionsContext , OptionsFn } from './options.context' ;
8
9
import { Client } from './reexports' ;
@@ -58,29 +59,36 @@ export class EdgeDB {
58
59
) : Promise < R > ;
59
60
60
61
async run ( query : any , args ?: any ) {
61
- if ( query instanceof TypedEdgeQL ) {
62
- const cardinality = InlineQueryCardinalityMap . get ( query . query ) ;
63
- if ( ! cardinality ) {
64
- throw new Error ( `Query was not found from inline query generation` ) ;
65
- }
66
- const exeMethod = cardinalityToExecutorMethod [ cardinality ] ;
62
+ try {
63
+ if ( query instanceof TypedEdgeQL ) {
64
+ const cardinality = InlineQueryCardinalityMap . get ( query . query ) ;
65
+ if ( ! cardinality ) {
66
+ throw new Error ( `Query was not found from inline query generation` ) ;
67
+ }
68
+ const exeMethod = cardinalityToExecutorMethod [ cardinality ] ;
67
69
68
- return await this . executor . current [ exeMethod ] ( query . query , args ) ;
69
- }
70
+ return await this . executor . current [ exeMethod ] ( query . query , args ) ;
71
+ }
70
72
71
- if ( query . run ) {
72
- // eslint-disable-next-line @typescript-eslint/return-await
73
- return await query . run ( this . executor . current , args ) ;
74
- }
73
+ if ( query . run ) {
74
+ // eslint-disable-next-line @typescript-eslint/return-await
75
+ return await query . run ( this . executor . current , args ) ;
76
+ }
75
77
76
- if ( typeof query === 'function' ) {
77
- // eslint-disable-next-line @typescript-eslint/return-await
78
- return await query ( this . executor . current , args ) ;
79
- }
78
+ if ( typeof query === 'function' ) {
79
+ // eslint-disable-next-line @typescript-eslint/return-await
80
+ return await query ( this . executor . current , args ) ;
81
+ }
80
82
81
- // For REPL, as this is untyped and assumes many/empty cardinality
82
- if ( typeof query === 'string' ) {
83
- return await this . executor . current . query ( query , args ) ;
83
+ // For REPL, as this is untyped and assumes many/empty cardinality
84
+ if ( typeof query === 'string' ) {
85
+ return await this . executor . current . query ( query , args ) ;
86
+ }
87
+ } catch ( e ) {
88
+ if ( ExclusivityViolationError . is ( e ) ) {
89
+ throw ExclusivityViolationError . cast ( e ) ;
90
+ }
91
+ throw e ;
84
92
}
85
93
86
94
throw new Error ( 'Could not figure out how to run given query' ) ;
0 commit comments