Skip to content

Commit 5bba56e

Browse files
committed
fix: properly throw ConflictRetriesExhaustedError instead of TransactionError
Previously, when the retries where exhausted and the last retry resulted in a conflict, a TransactionError was thrown that wrapped a ConflictRetriesExhaustedError. Now, we properly throw the ConflictRetriesExhaustedError. Also fixes the error message (it had a NonError: [object object] at the end instead of the original error message)
1 parent 22036b3 commit 5bba56e

File tree

2 files changed

+35
-13
lines changed

2 files changed

+35
-13
lines changed

src/database/arangodb/arangodb-adapter.ts

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,11 @@ export class ArangoDBAdapter implements DatabaseAdapter {
436436
transactionTimeoutMs: number | undefined;
437437
},
438438
): Error {
439+
if (error instanceof ConflictRetriesExhaustedError) {
440+
// this is returned in executeTransactionWithRetries()
441+
return error;
442+
}
443+
439444
// might be just something like a TypeError
440445
if (!isArangoError(error)) {
441446
return new TransactionError(error.message, error);
@@ -503,16 +508,33 @@ export class ArangoDBAdapter implements DatabaseAdapter {
503508
}
504509

505510
if (retries >= maxRetries) {
506-
// retries exhausted
507-
return {
508-
...result,
509-
timings,
510-
stats,
511-
databaseError: new ConflictRetriesExhaustedError({
512-
causedBy: result.databaseError,
513-
retries,
514-
}),
515-
};
511+
// retries exhausted. If it's a CONFLICT error, report in a special way
512+
if (
513+
isArangoError(result.databaseError) &&
514+
result.databaseError.errorNum === ERROR_ARANGO_CONFLICT
515+
) {
516+
const convertedCause = this.processDatabaseError(result.databaseError, {
517+
wasCancelled: false,
518+
hasTimedOut: false,
519+
transactionTimeoutMs: undefined,
520+
});
521+
return {
522+
...result,
523+
timings,
524+
stats,
525+
databaseError: new ConflictRetriesExhaustedError({
526+
causedBy: convertedCause,
527+
retries,
528+
}),
529+
};
530+
} else {
531+
// non-conflict error that just happened to occur on the last retry
532+
return {
533+
...result,
534+
timings,
535+
stats,
536+
};
537+
}
516538
}
517539

518540
const sleepStart = getPreciseTime();

src/execution/runtime-errors.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ export class ConflictRetriesExhaustedError extends ErrorWithCause {
3131
static readonly CODE = 'CONFLICT_RETRIES_EXHAUSTED';
3232

3333
readonly code = ConflictRetriesExhaustedError.CODE;
34+
readonly retries: number;
3435

3536
constructor({ causedBy, retries }: { causedBy: unknown; retries: number }) {
36-
super(`Operation detected conflicts and was aborted after ${retries} retries`, {
37-
causedBy,
38-
});
37+
super(`Operation detected conflicts and was aborted after ${retries} retries`, causedBy);
38+
this.retries = retries;
3939
}
4040
}

0 commit comments

Comments
 (0)