Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve extension errors #350

Merged
merged 2 commits into from
Aug 3, 2023
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion apps/extension/src/extension/ExtensionMessenger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export type Callback = (
) => Promise<RouterResult | void>;

export type Result<M> = {
error?: string;
error?: { message: string, stack: string };
return: Promise<M extends Message<infer R> ? R : never>;
};

Expand Down
5 changes: 4 additions & 1 deletion apps/extension/src/extension/ExtensionRequester.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ export class ExtensionRequester {
}

if (result.error) {
throw new Error(result.error);
const { message, stack } = result.error;
const error = new Error(message);
error.stack = stack;
throw error;
}

return result.return;
Expand Down
9 changes: 8 additions & 1 deletion apps/extension/src/extension/ExtensionRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,14 @@ export class ExtensionRouter extends Router {
return: result,
};
} catch (e) {
return Promise.resolve({ error: e });
if (!(e instanceof Error)) {
throw e;
}
// Error is not JSON-ifiable so we make a new object with the
// data needed to reconstruct the Error later.
// See https://github.com/anoma/namada-interface/issues/139
const { message, stack } = e;
return Promise.resolve({ error: { message, stack } });
}
}
}
3 changes: 3 additions & 0 deletions apps/extension/src/manifest/v2/_devOnly.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"content_security_policy": "script-src 'self' 'unsafe-eval'; object-src 'self';"
}
1 change: 1 addition & 0 deletions apps/extension/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"resolveJsonModule": true,
"skipLibCheck": true,
"strict": true,
"sourceMap": true,
"target": "es2015"
},
"include": ["src/**/*.ts", "src/**/*.tsx"],
Expand Down
10 changes: 8 additions & 2 deletions apps/extension/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const MANIFEST_VERSION = TARGET === "firefox" ? "v2" : "v3";
const MANIFEST_BASE_PATH = `./src/manifest/_base.json`;
const MANIFEST_BASE_VERSION_PATH = `./src/manifest/${MANIFEST_VERSION}/_base.json`;
const MANIFEST_PATH = `./src/manifest/${MANIFEST_VERSION}/${TARGET}.json`;
const MANIFEST_V2_DEV_ONLY_PATH = `./src/manifest/v2/_devOnly.json`;

const copyPatterns = [
{
Expand All @@ -41,7 +42,12 @@ const plugins = [
patterns: copyPatterns,
}),
new MergeJsonWebpackPlugin({
files: [MANIFEST_BASE_PATH, MANIFEST_BASE_VERSION_PATH, MANIFEST_PATH],
files: [
MANIFEST_BASE_PATH,
MANIFEST_BASE_VERSION_PATH,
MANIFEST_PATH,
...(NODE_ENV === "development" && TARGET === "firefox" ? [MANIFEST_V2_DEV_ONLY_PATH] : [])
],
output: {
fileName: "./manifest.json",
},
Expand Down Expand Up @@ -74,7 +80,7 @@ if (NODE_ENV === "development") {
module.exports = {
mode: NODE_ENV,
target: "web",
devtool: false,
devtool: TARGET === "firefox" ? "eval-source-map" : false,
entry: {
content: "./src/content",
background: "./src/background",
Expand Down
Loading