From 3a2fe169e8ce5ac2eef0c9f520e960984dccd362 Mon Sep 17 00:00:00 2001 From: austinyu12 Date: Sat, 5 Oct 2024 21:01:28 -0700 Subject: [PATCH 1/3] 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/3] 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}'`); } } From bb494a014f2bf2966123ed7f59a4a7b305be6fce Mon Sep 17 00:00:00 2001 From: austinyu12 Date: Tue, 8 Oct 2024 23:01:10 -0700 Subject: [PATCH 3/3] more verbose extension error made the extension error when validating a dictionary provide the cause of error --- ext/js/dictionary/dictionary-importer.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/ext/js/dictionary/dictionary-importer.js b/ext/js/dictionary/dictionary-importer.js index 13fbb7078c..e8a72ba821 100644 --- a/ext/js/dictionary/dictionary-importer.js +++ b/ext/js/dictionary/dictionary-importer.js @@ -373,10 +373,9 @@ export class DictionaryImporter { * @returns {ExtensionError} */ _formatAjvSchemaError(schema, fileName) { - const e2 = new ExtensionError(`Dictionary has invalid data in '${fileName}'`); - e2.data = schema.errors; - - return e2; + const e = new ExtensionError(`Dictionary has invalid data in '${fileName}' '${JSON.stringify(schema.errors)}'`); + e.data = schema.errors; + return e; } /**