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
- Store the workspace path used for the first successful
openDatabaseAt call in a module-level variable.
- 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
- Run
pnpm check — must pass.
- 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
Problem
initDatabaseshort-circuits onif (db) return;. If it is called a second time with a differentworkspacePath, the second call is silently ignored and writes continue going to the originally-opened database. A caller that should have usedreinitDatabasegets no feedback, and debugging "why are my writes not showing up" becomes very painful.Location
File:
packages/desktop/src/main/db/index.ts:168-171Fix Approach
openDatabaseAtcall in a module-level variable.Error('initDatabase called with different workspace path; use reinitDatabase to switch')— silent-ignore is the bug, so throwing is preferred over warning.Verification
pnpm check— must pass.initDatabase('/a'), theninitDatabase('/b')— expect a thrown error, not silent ignore.Context