Skip to content

Commit

Permalink
feat: clean stack on V8 engine
Browse files Browse the repository at this point in the history
  • Loading branch information
skarab42 committed Apr 4, 2022
1 parent e720c16 commit db32237
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
},
"packageManager": "[email protected]",
"devDependencies": {
"@types/node": "^17.0.23",
"@typescript-eslint/eslint-plugin": "^5.17.0",
"@typescript-eslint/parser": "^5.17.0",
"c8": "^7.11.0",
Expand Down
6 changes: 6 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export class PojoError<
readonly args: TArgs;
readonly data: TPojo;

constructor(type: TType, args: TArgs, data: TPojo) {
constructor(type: TType, args: TArgs, data: TPojo, caller: Function) {
super();

this.type = type;
Expand All @@ -84,6 +84,10 @@ export class PojoError<

this.message = data.message;

if (typeof Error.captureStackTrace === "function") {
Error.captureStackTrace(this, caller);
}

Object.setPrototypeOf(this, new.target.prototype);
}

Expand Down Expand Up @@ -127,7 +131,7 @@ export function factory<TErrorTypes extends PojoErrorTypes>(
const func = errors[type] as TErrorTypes[TType];
const data = func(...args) as ReturnType<TErrorTypes[TType]>;

return new PojoError(type, args, data);
return new PojoError(type, args, data, newError);
}

function throwError<TType extends keyof TErrorTypes>(
Expand Down
5 changes: 5 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
{
"env": {
"node": true,
"browser": true
},

"compilerOptions": {
// [Language and Environment]
"target": "ES2015",
Expand Down

0 comments on commit db32237

Please sign in to comment.