changeset 53:f2e066bbe343

Handle errors around reading the state database file.
author Ludovic Chabant <ludovic@chabant.com>
date Mon, 02 Oct 2023 10:07:26 -0700
parents 586f857a98dd
children 06504ceb3283
files src/main.ts
diffstat 1 files changed, 9 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/main.ts	Mon Oct 02 10:05:02 2023 -0700
+++ b/src/main.ts	Mon Oct 02 10:07:26 2023 -0700
@@ -487,9 +487,15 @@
 		const fs = this.app.vault.adapter;
 		if (await fs.exists(path)) {
 			const jsonDb = await fs.read(path);
-			this.data = JSON.parse(jsonDb);
-			const numLoaded = Object.keys(this.data.rememberedFiles).length;
-			console.debug(`RememberFileState: read ${numLoaded} record from state database.`);
+			try
+			{
+				this.data = JSON.parse(jsonDb);
+				const numLoaded = Object.keys(this.data.rememberedFiles).length;
+				console.debug(`RememberFileState: read ${numLoaded} record from state database.`);
+			} catch (err) {
+				console.error("RememberFileState: error loading state database:", err);
+				console.error(jsonDb);
+			}
 		}
 	}