Skip to content

Commit

Permalink
Improve error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Fryuni committed Oct 7, 2024
1 parent 9f73434 commit 318eac9
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions packages/db/src/core/cli/migration-queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import type {
TextColumn,
} from '../types.js';
import type { RemoteDatabaseInfo, Result } from '../utils.js';
import { LibsqlError } from '@libsql/client';

const sqlite = new SQLiteAsyncDialect();
const genTempTableName = customAlphabet('abcdefghijklmnopqrstuvwxyz', 10);
Expand Down Expand Up @@ -450,10 +451,19 @@ async function getDbCurrentSnapshot(
);

return JSON.parse(res.snapshot);
} catch (error: any) {
if (error.code === 'SQLITE_UNKNOWN' || (error.code === 'SQLITE_ERROR' && error.rawCode === 1)) {
} catch (error) {
// Don't handle errors that are not from libSQL
if (error instanceof LibsqlError &&
// If the schema was never pushed to the database yet the table won't exist.
// Treat a missing snapshot table as an empty table.
(
// When connecting to a remote database in that condition
// the query will fail with the following error code and message.
(error.code === 'SQLITE_UNKNOWN' && error.message === 'SQLITE_UNKNOWN: SQLite error: no such table: _astro_db_snapshot') ||
// When connecting to a local or in-memory database that does not have a snapshot table yet
// the query will fail with the following error code and message.
(error.code === 'SQLITE_ERROR' && error.message === 'SQLITE_ERROR: no such table: _astro_db_snapshot'))
) {
return;
}

Expand Down

0 comments on commit 318eac9

Please sign in to comment.