Skip to content
This repository has been archived by the owner on Jan 17, 2023. It is now read-only.

Commit

Permalink
Protect against an empty response (#3037)
Browse files Browse the repository at this point in the history
This happened in some weird corner case while debugging
  • Loading branch information
ianb authored and jaredhirsch committed Jun 14, 2017
1 parent e1fceed commit 14df39d
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions addon/webextension/selector/callBackground.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

this.callBackground = function callBackground(funcName, ...args) {
return browser.runtime.sendMessage({funcName, args}).then((result) => {
if (result.type === "success") {
if (result && result.type === "success") {
return result.value;
} else if (result.type === "error") {
let exc = new Error(result.message);
} else if (result && result.type === "error") {
let exc = new Error(result.message || "Unknown error");
exc.name = "BackgroundError";
if ('errorCode' in result) {
exc.errorCode = result.errorCode;
Expand All @@ -18,8 +18,8 @@ this.callBackground = function callBackground(funcName, ...args) {
throw exc;
} else {
log.error("Unexpected background result:", result);
let exc = new Error(`Bad response type from background page: ${result.type || undefined}`);
exc.resultType = result.type || "undefined";
let exc = new Error(`Bad response type from background page: ${result && result.type || undefined}`);
exc.resultType = result ? (result.type || "undefined") : "undefined result";
throw exc;
}
});
Expand Down

0 comments on commit 14df39d

Please sign in to comment.