summaryrefslogtreecommitdiff
path: root/ext/bg/js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2019-12-08 15:52:34 -0500
committertoasted-nutbread <toasted-nutbread@users.noreply.github.com>2019-12-08 16:01:29 -0500
commit2dad7f888b77c7c0293512076b719026f6b95de9 (patch)
treebfa67f43cebaee618e6f3c4f178db69e53a6dd05 /ext/bg/js
parent0156869a3d8c4236594035e072b084b7c2ea8f16 (diff)
Update how errors are reported when importing a dictionary
Diffstat (limited to 'ext/bg/js')
-rw-r--r--ext/bg/js/database.js13
-rw-r--r--ext/bg/js/settings/dictionaries.js16
-rw-r--r--ext/bg/js/util.js4
3 files changed, 16 insertions, 17 deletions
diff --git a/ext/bg/js/database.js b/ext/bg/js/database.js
index 2f624189..5aee2311 100644
--- a/ext/bg/js/database.js
+++ b/ext/bg/js/database.js
@@ -332,9 +332,10 @@ class Database {
return result;
}
- async importDictionary(archive, progressCallback, exceptions, details) {
+ async importDictionary(archive, progressCallback, details) {
this.validate();
+ const errors = [];
const prefixWildcardsSupported = details.prefixWildcardsSupported;
const maxTransactionLength = 1000;
@@ -351,11 +352,7 @@ class Database {
const objectStore = transaction.objectStore(objectStoreName);
await Database.bulkAdd(objectStore, items, i, count);
} catch (e) {
- if (exceptions) {
- exceptions.push(e);
- } else {
- throw e;
- }
+ errors.push(e);
}
}
};
@@ -496,7 +493,7 @@ class Database {
await bulkAdd('tagMeta', rows, total, current);
};
- return await Database.importDictionaryZip(
+ const result = await Database.importDictionaryZip(
archive,
indexDataLoaded,
termDataLoaded,
@@ -506,6 +503,8 @@ class Database {
tagDataLoaded,
details
);
+
+ return {result, errors};
}
validate() {
diff --git a/ext/bg/js/settings/dictionaries.js b/ext/bg/js/settings/dictionaries.js
index b5e663ea..a7205ae5 100644
--- a/ext/bg/js/settings/dictionaries.js
+++ b/ext/bg/js/settings/dictionaries.js
@@ -577,7 +577,6 @@ async function onDictionaryImport(e) {
}
};
- const exceptions = [];
const files = [...e.target.files];
const optionsFull = await apiOptionsGetFull();
@@ -593,21 +592,22 @@ async function onDictionaryImport(e) {
dictImportInfo.textContent = `(${i + 1} of ${ii})`;
}
- const summary = await utilDatabaseImport(files[i], updateProgress, exceptions, importDetails);
+ const {result, errors} = await utilDatabaseImport(files[i], updateProgress, importDetails);
for (const options of toIterable(await getOptionsArray())) {
const dictionaryOptions = SettingsDictionaryListUI.createDictionaryOptions();
dictionaryOptions.enabled = true;
- options.dictionaries[summary.title] = dictionaryOptions;
- if (summary.sequenced && options.general.mainDictionary === '') {
- options.general.mainDictionary = summary.title;
+ options.dictionaries[result.title] = dictionaryOptions;
+ if (result.sequenced && options.general.mainDictionary === '') {
+ options.general.mainDictionary = result.title;
}
}
await settingsSaveOptions();
- if (exceptions.length > 0) {
- exceptions.push(`Dictionary may not have been imported properly: ${exceptions.length} error${exceptions.length === 1 ? '' : 's'} reported.`);
- dictionaryErrorsShow(exceptions);
+ if (errors.length > 0) {
+ errors.push(...errors);
+ errors.push(`Dictionary may not have been imported properly: ${errors.length} error${errors.length === 1 ? '' : 's'} reported.`);
+ dictionaryErrorsShow(errors);
}
const optionsContext = getOptionsContext();
diff --git a/ext/bg/js/util.js b/ext/bg/js/util.js
index 93bb7047..fedfa466 100644
--- a/ext/bg/js/util.js
+++ b/ext/bg/js/util.js
@@ -106,13 +106,13 @@ function utilDatabaseDeleteDictionary(dictionaryName, onProgress) {
return utilBackend().translator.database.deleteDictionary(dictionaryName, onProgress);
}
-async function utilDatabaseImport(data, progress, exceptions, details) {
+async function utilDatabaseImport(data, progress, details) {
// Edge cannot read data on the background page due to the File object
// being created from a different window. Read on the same page instead.
if (EXTENSION_IS_BROWSER_EDGE) {
data = await utilReadFile(data);
}
- return utilBackend().translator.database.importDictionary(data, progress, exceptions, details);
+ return utilBackend().translator.database.importDictionary(data, progress, details);
}
function utilReadFile(file) {