fix(db): keep no folder in the migration repair line of the Journal (#478)

connectToProfile wrote the failure of repair_migrations with a raw
console.error. repair_migrations returns rusqlite's error unscrubbed, and
rusqlite appends the full path of a database it cannot open, so the line
carried every folder of that path, user name included, and could go with a
feedback report. It now goes through logError(withoutFolders(...)), like the
preparation line next to it.

Blocking finding B1 of the review of PR #491 (comment 27073); fixing it in
the stack is Max's decision of 2026-10-24.

Resolves #478

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
le king fu 2026-10-24 09:02:03 -04:00
commit 90a9a525cf
2 changed files with 20 additions and 1 deletions

View file

@ -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({

View file

@ -475,7 +475,10 @@ export function connectToProfile(dbFilename: string): Promise<void> {
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