diff options
author | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2021-07-13 20:19:48 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-07-13 20:19:48 -0400 |
commit | d5320c71a6b2219039d9e3d7c7fd4381f1c6b31d (patch) | |
tree | 5f343decda17360f3a43ac67c4668b23f3cf22c8 /ext/js/background/backend.js | |
parent | 437b588411590ad44991f16ed26e2b2f35505e89 (diff) |
Throw an error when _getProfile doesn't have a matching profile (#1826)
Diffstat (limited to 'ext/js/background/backend.js')
-rw-r--r-- | ext/js/background/backend.js | 31 |
1 files changed, 25 insertions, 6 deletions
diff --git a/ext/js/background/backend.js b/ext/js/background/backend.js index af847610..623f3612 100644 --- a/ext/js/background/backend.js +++ b/ext/js/background/backend.js @@ -996,14 +996,27 @@ class Backend { _getProfile(optionsContext, useSchema=false) { const options = this._getOptionsFull(useSchema); const profiles = options.profiles; - if (optionsContext.current) { - return profiles[options.profileCurrent]; + if (!optionsContext.current) { + // Specific index + const {index} = optionsContext; + if (typeof index === 'number') { + if (index < 0 || index >= profiles.length) { + throw this._createDataError(`Invalid profile index: ${index}`, optionsContext); + } + return profiles[index]; + } + // From context + const profile = this._getProfileFromContext(options, optionsContext); + if (profile !== null) { + return profile; + } } - if (typeof optionsContext.index === 'number') { - return profiles[optionsContext.index]; + // Default + const {profileCurrent} = options; + if (profileCurrent < 0 || profileCurrent >= profiles.length) { + throw this._createDataError(`Invalid current profile index: ${profileCurrent}`, optionsContext); } - const profile = this._getProfileFromContext(options, optionsContext); - return profile !== null ? profile : profiles[options.profileCurrent]; + return profiles[profileCurrent]; } _getProfileFromContext(options, optionsContext) { @@ -1030,6 +1043,12 @@ class Backend { return null; } + _createDataError(message, data) { + const error = new Error(message); + error.data = data; + return error; + } + _clearProfileConditionsSchemaCache() { this._profileConditionsSchemaCache = []; } |