diff --git a/docs/releases/unreleased.md b/docs/releases/unreleased.md index c29cde0dd..6bcd3b76b 100644 --- a/docs/releases/unreleased.md +++ b/docs/releases/unreleased.md @@ -34,6 +34,8 @@ When a change has user-facing documentation, include a canonical tasknotes.dev l ## Fixed +- Stop plugin startup when an existing settings file cannot be read, preserving it for recovery instead of starting services with default settings. + - (#1849) Fixed context menus stacking on top of each other. Only one menu stays open at a time, and clicking the same indicator again closes its menu. This previously applied to date fields only, and now covers priority, status, recurrence, reminders, task, ICS event, and batch menus. - Thanks to @3zra47 for reporting and @YBKF for the contribution. diff --git a/src/main.ts b/src/main.ts index 4a967ff72..d1fe8ad43 100644 --- a/src/main.ts +++ b/src/main.ts @@ -744,6 +744,10 @@ export default class TaskNotesPlugin extends Plugin { }, }); } + if (result.compromised) + throw new Error( + "TaskNotes settings are unreadable; restore settings before loading the plugin." + ); return result.data; } diff --git a/tests/unit/issues/issue-1591-settings-lost-on-update.test.ts b/tests/unit/issues/issue-1591-settings-lost-on-update.test.ts index bcd377f6e..4f151779d 100644 --- a/tests/unit/issues/issue-1591-settings-lost-on-update.test.ts +++ b/tests/unit/issues/issue-1591-settings-lost-on-update.test.ts @@ -38,8 +38,8 @@ describe("issue #1591 settings reset on update", () => { const plugin = createPlugin({ dataFileExists: true }); plugin.loadData = jest.fn().mockResolvedValue(null); - await plugin.loadSettings(); - await plugin.checkForVersionUpdate(); + await expect(plugin.loadSettings()).rejects.toThrow("settings are unreadable"); + await plugin.saveSettingsDataOnly(); expect(plugin.loadData).toHaveBeenCalledTimes(4); expect(plugin.saveData).not.toHaveBeenCalled();