Skip to content

[Bug] initDatabase silently ignores a different workspace path on repeat calls #392

@samzong

Description

@samzong

Problem

initDatabase short-circuits on if (db) return;. If it is called a second time with a different workspacePath, the second call is silently ignored and writes continue going to the originally-opened database. A caller that should have used reinitDatabase gets no feedback, and debugging "why are my writes not showing up" becomes very painful.

Location

File: packages/desktop/src/main/db/index.ts:168-171

export function initDatabase(workspacePath: string): void {
  if (db) return;
  openDatabaseAt(workspacePath);
}

Fix Approach

  1. Store the workspace path used for the first successful openDatabaseAt call in a module-level variable.
  2. On repeat calls, compare the incoming path against the stored one:
    • Same path: return early as today.
    • Different path: throw an explicit error like Error('initDatabase called with different workspace path; use reinitDatabase to switch') — silent-ignore is the bug, so throwing is preferred over warning.

Verification

  1. Run pnpm check — must pass.
  2. Unit test: call initDatabase('/a'), then initDatabase('/b') — expect a thrown error, not silent ignore.

Context

  • WG: Artifact & File System
  • Priority: Low
  • Estimated effort: 15-20 minutes

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/artifactArtifact & File System WGhelp wantedExtra attention is neededkind/bugCategorizes issue or PR as related to a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions