Skip to content

Commit

Permalink
Improve error display
Browse files Browse the repository at this point in the history
  • Loading branch information
fregante committed Nov 11, 2023
1 parent 4e34b79 commit aafeba3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion source/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ import type { Browser } from "webextension-polyfill";

declare global {
const browser: Browser;
// eslint-disable-next-line no-var -- https://stackoverflow.com/a/69208755/288906
// eslint-disable-next-line no-var -- `let/const` behave differently https://stackoverflow.com/a/69208755/288906
var __webextMessenger: string;
}
12 changes: 6 additions & 6 deletions source/thisTarget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,16 +176,16 @@ export function initPrivateApi(): void {
// Improve DX by informing the developer that it's being loaded the wrong way
// https://github.com/pixiebrix/webext-messenger/issues/88
if (globalThis.__webextMessenger) {
// TODO: Use Error#cause after https://bugs.chromium.org/p/chromium/issues/detail?id=1211260

Check warning on line 179 in source/thisTarget.ts

View workflow job for this annotation

GitHub Actions / Lint

Unexpected 'todo' comment: 'TODO: Use Error#cause after...'

Check warning on line 179 in source/thisTarget.ts

View workflow job for this annotation

GitHub Actions / Lint

Unexpected 'todo' comment: 'TODO: Use Error#cause after...'
console.log(globalThis.__webextMessenger.replace(/^Error: /, ""));
console.error(
"webext-messenger has already been imported in this context. This is a fatal error.\nhttps://github.com/pixiebrix/webext-messenger/issues/88",
{
existing: globalThis.__webextMessenger,
current: import.meta.url,
}
"webext-messenger: Duplicate execution. This is a fatal error.\nhttps://github.com/pixiebrix/webext-messenger/issues/88"
);
return;
}

globalThis.__webextMessenger = import.meta.url;
// Use Error to capture the stack and make it easier to find the cause
globalThis.__webextMessenger = new Error("First execution").stack!;
if (isExtensionContext()) {
// Only `runtime` pages can handle this message but I can't remove it because its listener
// also serves the purpose of throwing a specific error when no methods have been registered.
Expand Down

0 comments on commit aafeba3

Please sign in to comment.