Skip to content

Commit

Permalink
obs-store/local-store should upgrade webextension error to real error (
Browse files Browse the repository at this point in the history
…#7207)

* obs-store/local-store should upgrade webextension error to real error

* lint fix

* local-store - allow lastError through unchanged if error-like
  • Loading branch information
kumavis authored Sep 23, 2019
1 parent 8a1ddbb commit f5b2977
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions app/scripts/lib/local-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ module.exports = class ExtensionStore {
const local = extension.storage.local
return new Promise((resolve, reject) => {
local.get(null, (/** @type {any} */ result) => {
const err = extension.runtime.lastError
const err = checkForError()
if (err) {
reject(err)
} else {
Expand All @@ -69,7 +69,7 @@ module.exports = class ExtensionStore {
const local = extension.storage.local
return new Promise((resolve, reject) => {
local.set(obj, () => {
const err = extension.runtime.lastError
const err = checkForError()
if (err) {
reject(err)
} else {
Expand All @@ -88,3 +88,17 @@ module.exports = class ExtensionStore {
function isEmpty (obj) {
return Object.keys(obj).length === 0
}

/**
* Returns an Error if extension.runtime.lastError is present
* this is a workaround for the non-standard error object thats used
* @returns {Error}
*/
function checkForError () {
const lastError = extension.runtime.lastError
if (!lastError) return
// if it quacks like an Error, its an Error
if (lastError.stack && lastError.message) return lastError
// repair incomplete error object (eg chromium v77)
return new Error(lastError.message)
}

0 comments on commit f5b2977

Please sign in to comment.