From 576a5138b01fd46dc7c0d3431a78bedfc510ecb5 Mon Sep 17 00:00:00 2001 From: Lucas Van Mol Date: Mon, 4 Dec 2023 18:26:16 +0100 Subject: [PATCH] Remove generating latex.. message when there is an error --- src/main.ts | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/main.ts b/src/main.ts index 17fec8e..2cde4ed 100644 --- a/src/main.ts +++ b/src/main.ts @@ -181,8 +181,16 @@ export default class LatexOCR extends Plugin { const imgpath = path.join(this.pluginPath, `/.clipboard_images/pasted_image.${filetype}`); fs.writeFileSync(imgpath, buffer) - // Get latex - const latex = await this.model.imgfileToLatex(imgpath) + let latex; + try { + // Get latex + latex = await this.model.imgfileToLatex(imgpath) + } catch (err) { + // If err, return empty string so that we erase `fullMessage` + latex = "" + new Notice(`⚠️ ${err} `, 5000) + console.error(err) + } // Find generating message again, starting search from original line // (it may have moved up or down) @@ -196,7 +204,9 @@ export default class LatexOCR extends Plugin { const from = text.indexOf(fullMessage) if (from !== -1) { editor.replaceRange(latex, { line: currLine, ch: from }, { line: currLine, ch: from + fullMessage.length }) - new Notice(`🪄 Latex pasted to note`) + if (latex !== "") { + new Notice(`🪄 Latex pasted to note`) + } return } currLine += currOffset;