From 8f2ae437c658205da99b18b7a4261cfca7f21218 Mon Sep 17 00:00:00 2001 From: vorotamoroz Date: Mon, 20 Feb 2023 17:54:57 +0900 Subject: [PATCH] Fixed: - Now reading error will be reported. --- src/lib | 2 +- src/main.ts | 26 +++++++++++++++++++++++--- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/lib b/src/lib index e4d825a..fbb3fcd 160000 --- a/src/lib +++ b/src/lib @@ -1 +1 @@ -Subproject commit e4d825ae13e4a591be0598cf9661ee0651f0a58c +Subproject commit fbb3fcd8b479035b82e5ffeb3a68ade51a4c28b7 diff --git a/src/main.ts b/src/main.ts index 4f9e796..3269d20 100644 --- a/src/main.ts +++ b/src/main.ts @@ -2714,7 +2714,13 @@ export default class ObsidianLiveSyncPlugin extends Plugin { Logger(`Reading : ${file.path}`, LOG_LEVEL.VERBOSE); const contentBin = await this.app.vault.readBinary(file); Logger(`Processing: ${file.path}`, LOG_LEVEL.VERBOSE); - content = await arrayBufferToBase64(contentBin); + try { + content = await arrayBufferToBase64(contentBin); + } catch (ex) { + Logger(`The file ${file.path} could not be encoded`); + Logger(ex, LOG_LEVEL.VERBOSE); + return false; + } datatype = "newnote"; } else { content = await this.app.vault.read(file); @@ -2722,7 +2728,14 @@ export default class ObsidianLiveSyncPlugin extends Plugin { } } else { if (cache instanceof ArrayBuffer) { - content = await arrayBufferToBase64(cache); + Logger(`Processing: ${file.path}`, LOG_LEVEL.VERBOSE); + try { + content = await arrayBufferToBase64(cache); + } catch (ex) { + Logger(`The file ${file.path} could not be encoded`); + Logger(ex, LOG_LEVEL.VERBOSE); + return false; + } datatype = "newnote" } else { content = cache; @@ -3071,7 +3084,14 @@ export default class ObsidianLiveSyncPlugin extends Plugin { async storeInternalFileToDatabase(file: InternalFileInfo, forceWrite = false) { const id = filename2idInternalMetadata(path2id(file.path)); const contentBin = await this.app.vault.adapter.readBinary(file.path); - const content = await arrayBufferToBase64(contentBin); + let content: string[]; + try { + content = await arrayBufferToBase64(contentBin); + } catch (ex) { + Logger(`The file ${file.path} could not be encoded`); + Logger(ex, LOG_LEVEL.VERBOSE); + return false; + } const mtime = file.mtime; return await runWithLock("file-" + id, false, async () => { try {