Skip to content

[Bug] DB migration catch blocks swallow all errors including real failures #233

@samzong

Description

@samzong

What happened?

Every ALTER TABLE ADD COLUMN migration in the database initialization is wrapped in a bare try {} catch {} block. This is meant to handle the "column already exists" case, but it also silently swallows genuine errors like type mismatches, disk I/O failures, or permission errors. The schema can end up partially applied with no visibility into what failed.

Where

packages/desktop/src/main/db/index.ts — there are 8 bare catch {} blocks wrapping ALTER TABLE statements.

How to fix

  1. Open packages/desktop/src/main/db/index.ts
  2. Find all bare catch {} blocks wrapping ALTER TABLE ADD COLUMN statements (there are 8)
  3. Replace each bare catch {} with a catch that checks the error message before swallowing:
try {
  sqlite.exec(`ALTER TABLE tasks ADD COLUMN gateway_id TEXT NOT NULL DEFAULT ''`);
} catch (e: unknown) {
  const msg = e instanceof Error ? e.message : String(e);
  if (!msg.includes("duplicate column") && !msg.includes("already exists")) {
    console.error("[db:migration]", msg);
  }
}
  1. Apply the same pattern to all 8 catch blocks
  2. Run pnpm check to verify nothing breaks

Expected outcome

Expected errors (duplicate column) are silently handled as before. Unexpected errors (disk I/O, type mismatch) are logged so they can be debugged.

Affected area

Task execution

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/artifactArtifact & File System WGbugSomething isn't workinggood first issueGood for newcomers

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions