diff --git a/packages/db/src/core/cli/commands/execute/index.ts b/packages/db/src/core/cli/commands/execute/index.ts index 9a5a1b8e2f90..77b56a41c5ea 100644 --- a/packages/db/src/core/cli/commands/execute/index.ts +++ b/packages/db/src/core/cli/commands/execute/index.ts @@ -16,6 +16,7 @@ import { import { bundleFile, importBundledFile } from '../../../load-file.js'; import type { DBConfig } from '../../../types.js'; import { getManagedRemoteToken } from '../../../utils.js'; +import { isDbError } from '../../../../runtime/virtual.js'; export async function cmd({ astroConfig, @@ -64,7 +65,7 @@ export async function cmd({ await mod.default(); console.info(`${green('✔')} File run successfully.`); } catch (e) { - if (e instanceof LibsqlError) { + if (isDbError(e)) { throw new Error(EXEC_ERROR(e.message)); } throw e; diff --git a/packages/db/src/core/cli/migration-queries.ts b/packages/db/src/core/cli/migration-queries.ts index bd6360665d4e..b53fdabc1e60 100644 --- a/packages/db/src/core/cli/migration-queries.ts +++ b/packages/db/src/core/cli/migration-queries.ts @@ -37,6 +37,7 @@ import type { TextColumn, } from '../types.js'; import type { RemoteDatabaseInfo, Result } from '../utils.js'; +import { isDbError } from '../../runtime/virtual.js'; const sqlite = new SQLiteAsyncDialect(); const genTempTableName = customAlphabet('abcdefghijklmnopqrstuvwxyz', 10); @@ -454,7 +455,7 @@ async function getDbCurrentSnapshot( } catch (error) { // Don't handle errors that are not from libSQL if ( - error instanceof LibsqlError && + isDbError(error) && // If the schema was never pushed to the database yet the table won't exist. // Treat a missing snapshot table as an empty table. diff --git a/packages/db/src/core/integration/index.ts b/packages/db/src/core/integration/index.ts index 6debb40176ab..a8f838f8a468 100644 --- a/packages/db/src/core/integration/index.ts +++ b/packages/db/src/core/integration/index.ts @@ -3,7 +3,6 @@ import { mkdir, writeFile } from 'node:fs/promises'; import { dirname } from 'node:path'; import { fileURLToPath } from 'node:url'; import type { ManagedAppToken } from '@astrojs/studio'; -import { LibsqlError } from '@libsql/client'; import type { AstroConfig, AstroIntegration } from 'astro'; import { blue, yellow } from 'kleur/colors'; import { @@ -15,7 +14,8 @@ import { mergeConfig, } from 'vite'; import parseArgs from 'yargs-parser'; -import { AstroDbError } from '../../runtime/utils.js'; +import { AstroDbError, } from '../../runtime/utils.js'; +import { isDbError } from '../../runtime/virtual.js'; import { CONFIG_FILE_NAMES, DB_PATH } from '../consts.js'; import { EXEC_DEFAULT_EXPORT_ERROR, EXEC_ERROR } from '../errors.js'; import { resolveDbConfig } from '../load-file.js'; @@ -209,7 +209,7 @@ async function executeSeedFile({ try { await mod.default(); } catch (e) { - if (e instanceof LibsqlError) { + if (isDbError(e)) { throw new AstroDbError(EXEC_ERROR(e.message)); } throw e; diff --git a/packages/db/src/runtime/virtual.ts b/packages/db/src/runtime/virtual.ts index d6b50451875b..bed91c65d3c7 100644 --- a/packages/db/src/runtime/virtual.ts +++ b/packages/db/src/runtime/virtual.ts @@ -1,4 +1,4 @@ -import type { LibsqlError } from '@libsql/client'; +import { LibsqlError } from '@libsql/client'; import { sql as _sql } from 'drizzle-orm'; import type { BooleanColumnInput, diff --git a/packages/db/test/test-utils.js b/packages/db/test/test-utils.js index 8315e85512fa..c69220ecb846 100644 --- a/packages/db/test/test-utils.js +++ b/packages/db/test/test-utils.js @@ -142,7 +142,7 @@ function createRemoteDbServer() { JSON.stringify({ success: false, error: { - code: e instanceof LibsqlError ? e.code : 'SQLITE_QUERY_FAILED', + code: isDbError(e) ? e.code : 'SQLITE_QUERY_FAILED', details: e.message, }, }),