Skip to content

Commit

Permalink
ensure Error.captureStackTrace is only used in the correct envs
Browse files Browse the repository at this point in the history
  • Loading branch information
TarikGul committed Jan 17, 2024
1 parent 0c61913 commit dbbcb47
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/errors/BaseError.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
// Copyright 2023 Parity Technologies (UK) Ltd.

import { JS_ENV } from '../consts';
import { WindowChrome } from './types';

/**
* Errors that may be returned by the API.
*/
Expand Down Expand Up @@ -76,6 +79,9 @@ export class BaseError extends Error {
constructor(message: string, error?: BaseErrorsEnum) {
super(message);
this.name = error || this.constructor.name;
Error.captureStackTrace(this, this.constructor);
// Only runtimes built on v8 will have `Error.captureStackTrace`.
if (JS_ENV === 'node' || (window && (window as WindowChrome).chrome)) {
Error.captureStackTrace(this, this.constructor);
}
}
}
4 changes: 4 additions & 0 deletions src/errors/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,7 @@ export interface CheckXcmTxInputsOpts {
isLimited?: boolean;
weightLimit?: { refTime?: string; proofSize?: string };
}

export interface WindowChrome extends Window {
chrome?: unknown;
}

0 comments on commit dbbcb47

Please sign in to comment.