Skip to content

Commit c6e43c6

Browse files
Copilotbitnimble
andcommitted
chore: use DatabaseError from pg-protocol for proper error typing
Co-authored-by: bitnimble <4076797+bitnimble@users.noreply.github.com>
1 parent 88ab683 commit c6e43c6

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

src/services/jest_global_setup.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { loadEnvConfig } from '@next/env';
22
import * as fs from 'fs/promises';
33
import * as path from 'path';
44
import pg from 'pg';
5+
import { DatabaseError } from 'pg-protocol';
56

67
const projectDir = process.cwd();
78
loadEnvConfig(projectDir);
@@ -62,11 +63,11 @@ export default async function globalSetup() {
6263
const sql = await fs.readFile(filePath, 'utf-8');
6364
await testPool.query(sql);
6465
} catch (e: unknown) {
65-
const pgError = e as { code?: string };
6666
// 42P07 = duplicate_table, 42710 = duplicate_object — schema already applied
67-
if (pgError.code !== '42P07' && pgError.code !== '42710') {
68-
console.warn(`Warning: failed to apply ${file}:`, e);
67+
if (e instanceof DatabaseError && (e.code === '42P07' || e.code === '42710')) {
68+
continue;
6969
}
70+
console.warn(`Warning: failed to apply ${file}:`, e);
7071
}
7172
}
7273
} finally {

0 commit comments

Comments
 (0)