Compare commits

...
Author SHA1 Message Date
Stanisław Chmiela 9c692afbcb fix: classify PostgreSQL lock timeouts as transient 2026-10-05 17:46:12 +02:00
2 changed files with 20 additions and 0 deletions

No files matched your search

@@ -1,8 +1,26 @@
import { EntityDatabaseAdapterTransientError, EntityErrorState } from '@expo/entity';
import { describe, expect, it } from '@jest/globals';
import { wrapNativePostgresCallAsync } from '../wrapNativePostgresCallAsync.ts';
describe(wrapNativePostgresCallAsync, () => {
it('classifies a PostgreSQL lock timeout as transient and preserves the cause', async () => {
const error = Object.assign(new Error('canceling statement due to lock timeout'), {
code: '55P03',
});
const result = wrapNativePostgresCallAsync(async () => {
throw error;
});
await expect(result).rejects.toBeInstanceOf(EntityDatabaseAdapterTransientError);
await expect(result).rejects.toMatchObject({
state: EntityErrorState.TRANSIENT,
message: error.message,
stack: error.stack,
cause: error,
});
});
it('rethrows literals', async () => {
const throwingFn = async (): Promise<void> => {
// eslint-disable-next-line no-throw-literal,@typescript-eslint/only-throw-error
@@ -38,6 +38,8 @@ function translatePostgresError(
return new EntityDatabaseAdapterCheckConstraintError(error.message, error);
case '23P01':
return new EntityDatabaseAdapterExclusionConstraintError(error.message, error);
case '55P03':
return new EntityDatabaseAdapterTransientError(error.message, error);
default:
return new EntityDatabaseAdapterUnknownError(error.message, error);
}