diff options
author | Kuuuube <61125188+Kuuuube@users.noreply.github.com> | 2024-05-14 01:40:11 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-05-14 05:40:11 +0000 |
commit | e73e0817be92b86d45a0bc3cb26601186afc34f5 (patch) | |
tree | 2a91df1701d342935b33e2a5f2d5c3ca1e44ec6d /ext | |
parent | c9d704733f9e832d3af4b393fe55e4c3cdc208d0 (diff) |
Catch and handle errors if getOptionsFull fails (#930)
Diffstat (limited to 'ext')
-rw-r--r-- | ext/js/pages/settings/dictionary-import-controller.js | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/ext/js/pages/settings/dictionary-import-controller.js b/ext/js/pages/settings/dictionary-import-controller.js index ecfadc1f..7ed61fc3 100644 --- a/ext/js/pages/settings/dictionary-import-controller.js +++ b/ext/js/pages/settings/dictionary-import-controller.js @@ -242,13 +242,15 @@ export class DictionaryImportController { return errors; } - void this._settingsController.application.api.triggerDatabaseUpdated('dictionary', 'import'); const errors2 = await this._addDictionarySettings(result.sequenced, result.title); + await this._settingsController.application.api.triggerDatabaseUpdated('dictionary', 'import'); + if (errors.length > 0) { - const allErrors = [...errors, ...errors2]; - allErrors.push(new Error(`Dictionary may not have been imported properly: ${allErrors.length} error${allErrors.length === 1 ? '' : 's'} reported.`)); - this._showErrors(allErrors); + errors.push(new Error(`Dictionary may not have been imported properly: ${errors.length} error${errors.length === 1 ? '' : 's'} reported.`)); + this._showErrors([...errors, ...errors2]); + } else if (errors2.length > 0) { + this._showErrors(errors2); } } @@ -258,7 +260,18 @@ export class DictionaryImportController { * @returns {Promise<Error[]>} */ async _addDictionarySettings(sequenced, title) { - const optionsFull = await this._settingsController.getOptionsFull(); + let optionsFull; + // Workaround Firefox bug sometimes causing getOptionsFull to fail + for (let i = 0, success = false; (i < 10) && (success === false); i++) { + try { + optionsFull = await this._settingsController.getOptionsFull(); + success = true; + } catch (error) { + log.error(error); + } + } + if (!optionsFull) { return [new Error('Failed to automatically set dictionary settings. A page refresh and manual enabling of the dictionary may be required.')]; } + const profileIndex = this._settingsController.profileIndex; /** @type {import('settings-modifications').Modification[]} */ const targets = []; |