diff --git a/src/services/db.test.ts b/src/services/db.test.ts index 8bc5f83..90b35cf 100644 --- a/src/services/db.test.ts +++ b/src/services/db.test.ts @@ -598,6 +598,22 @@ describe("a profile is prepared before the plugin opens it (#390)", () => { ); }); + it("writes no folder when the checksum repair fails with a path (#478)", async () => { + // rusqlite appends the full path of a database it cannot open, and + // repair_migrations returns that message as it is. + vi.mocked(invoke).mockImplementationOnce(async () => { + throw "Cannot open database: unable to open database file: C:\\Users\\Jean (Work) Smith\\AppData\\Roaming\\com.simpl.resultat\\profile_0a1b2c3d.db"; + }); + + await connectToProfile("profile_0a1b2c3d.db"); + + expect(vi.mocked(invoke).mock.calls[0][0]).toBe("repair_migrations"); + expect(Database.load).toHaveBeenCalledWith("sqlite:profile_0a1b2c3d.db"); + expect(vi.mocked(logError).mock.calls.map((call) => call[0])).toEqual([ + "Migration repair failed: Cannot open database: unable to open database file: profile_0a1b2c3d.db", + ]); + }); + it("names the copy in the Journal when the catch-up stopped after taking it (#395)", async () => { h.prepare = async () => report({ diff --git a/src/services/db.ts b/src/services/db.ts index 6ce783f..2897f69 100644 --- a/src/services/db.ts +++ b/src/services/db.ts @@ -475,7 +475,10 @@ export function connectToProfile(dbFilename: string): Promise { console.warn("Migration checksums repaired for", dbFilename); } } catch (e) { - console.error("Migration repair failed:", e); + // repair_migrations returns rusqlite's error unscrubbed, and rusqlite + // appends the full path of a database it cannot open: only the file + // name may reach the Journal (#478). + logError(withoutFolders(`Migration repair failed: ${e instanceof Error ? e.message : String(e)}`)); } // Catch a secondary profile up on the migrations tauri-plugin-sql never // runs for it, and repair legacy values in every profile (#390). Fails