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

Add support for Error.prototype.cause #296

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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: 2 additions & 0 deletions src/plainer.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
isArray,
isEmptyObject,
isError,
isMap,
isPlainObject,
isPrimitive,
Expand Down Expand Up @@ -95,6 +96,7 @@ const isDeep = (object: any, superJson: SuperJSON): boolean =>
isArray(object) ||
isMap(object) ||
isSet(object) ||
isError(object) ||
isInstanceOfRegisteredClass(object, superJson);

function addIdentity(object: any, path: any[], identities: Map<any, any[][]>) {
Expand Down
6 changes: 3 additions & 3 deletions src/transformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,18 @@

export type PrimitiveTypeAnnotation = 'number' | 'undefined' | 'bigint';

type LeafTypeAnnotation =

Check failure on line 22 in src/transformer.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

Replace `⏎··|·PrimitiveTypeAnnotation⏎··|·'regexp'⏎··|·'Date'⏎·` with `·PrimitiveTypeAnnotation·|·'regexp'·|·'Date'`

Check failure on line 22 in src/transformer.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

Replace `⏎··|·PrimitiveTypeAnnotation⏎··|·'regexp'⏎··|·'Date'⏎·` with `·PrimitiveTypeAnnotation·|·'regexp'·|·'Date'`

Check failure on line 22 in src/transformer.ts

View workflow job for this annotation

GitHub Actions / build (16.x)

Replace `⏎··|·PrimitiveTypeAnnotation⏎··|·'regexp'⏎··|·'Date'⏎·` with `·PrimitiveTypeAnnotation·|·'regexp'·|·'Date'`
| PrimitiveTypeAnnotation
| 'regexp'
| 'Date'
| 'Error'
| 'URL';

type TypedArrayAnnotation = ['typed-array', string];
type ClassTypeAnnotation = ['class', string];
type SymbolTypeAnnotation = ['symbol', string];
type CustomTypeAnnotation = ['custom', string];

type SimpleTypeAnnotation = LeafTypeAnnotation | 'map' | 'set';
type SimpleTypeAnnotation = LeafTypeAnnotation | 'map' | 'set' | 'Error';

type CompositeTypeAnnotation =
| TypedArrayAnnotation
Expand Down Expand Up @@ -90,6 +89,7 @@
const baseError: any = {
name: v.name,
message: v.message,
cause: v.cause

Check failure on line 92 in src/transformer.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

Insert `,`

Check failure on line 92 in src/transformer.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

Insert `,`

Check failure on line 92 in src/transformer.ts

View workflow job for this annotation

GitHub Actions / build (16.x)

Insert `,`
};

superJson.allowedErrorProps.forEach(prop => {
Expand All @@ -99,7 +99,7 @@
return baseError;
},
(v, superJson) => {
const e = new Error(v.message);
const e = new Error(v.message, { cause: v.cause });
e.name = v.name;
e.stack = v.stack;

Expand Down
Loading