From e73e0817be92b86d45a0bc3cb26601186afc34f5 Mon Sep 17 00:00:00 2001 From: Kuuuube <61125188+Kuuuube@users.noreply.github.com> Date: Tue, 14 May 2024 01:40:11 -0400 Subject: Catch and handle errors if getOptionsFull fails (#930) --- .../pages/settings/dictionary-import-controller.js | 23 +++++++++++++++++----- 1 file 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} */ 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 = []; -- cgit v1.2.3