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

Protect against an empty response #3037

Merged
merged 1 commit into from
Jun 14, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you'll need to guard against result being undefined in these "foo" in result clauses, too. They'll throw if result is falsy.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, we're inside a result && check here. Sorry!

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