From 3a2fe169e8ce5ac2eef0c9f520e960984dccd362 Mon Sep 17 00:00:00 2001 From: austinyu12 Date: Sat, 5 Oct 2024 21:01:28 -0700 Subject: [PATCH 1/2] syntax error message more verbose made the syntax error when validating a dictionary also provide the name of the term bank that contains the error --- ext/js/dictionary/dictionary-importer.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/ext/js/dictionary/dictionary-importer.js b/ext/js/dictionary/dictionary-importer.js index a558853e6e..aa579098f9 100644 --- a/ext/js/dictionary/dictionary-importer.js +++ b/ext/js/dictionary/dictionary-importer.js @@ -815,8 +815,19 @@ export class DictionaryImporter { const results = []; for (const file of files) { const content = await this._getData(file, new TextWriter()); - /** @type {unknown} */ - const entries = parseJson(content); + let entries; + + try { + /** @type {unknown} */ + entries = parseJson(content); + } + catch (error) { + if (error instanceof Error) { + let newError = new Error(error.message + `. Dictionary has invalid data in '${file.filename}'`); + console.error(newError); + throw newError; + } + } startIndex = progressData.index; this._progress(); From a7e9ee594d46ffb18640d74178f3ea9e7085fb47 Mon Sep 17 00:00:00 2001 From: austinyu12 Date: Sat, 5 Oct 2024 22:09:07 -0700 Subject: [PATCH 2/2] removed unnecessary error logging and fixed syntax --- ext/js/dictionary/dictionary-importer.js | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/ext/js/dictionary/dictionary-importer.js b/ext/js/dictionary/dictionary-importer.js index aa579098f9..13fbb7078c 100644 --- a/ext/js/dictionary/dictionary-importer.js +++ b/ext/js/dictionary/dictionary-importer.js @@ -820,12 +820,9 @@ export class DictionaryImporter { try { /** @type {unknown} */ entries = parseJson(content); - } - catch (error) { + } catch (error) { if (error instanceof Error) { - let newError = new Error(error.message + `. Dictionary has invalid data in '${file.filename}'`); - console.error(newError); - throw newError; + throw new Error(error.message + ` in '${file.filename}'`); } }