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

Error objects are serialized to {} #135

Open
wujekbogdan opened this issue Dec 7, 2021 · 4 comments · May be fixed by #136
Open

Error objects are serialized to {} #135

wujekbogdan opened this issue Dec 7, 2021 · 4 comments · May be fixed by #136

Comments

@wujekbogdan
Copy link

When I do:

import serializeJavascript from 'serialize-javascript';
const serialized = serializeJavascript({  error: new Error('message') });

console.log(serialized);

I'm receiving:

"{\"error\":{}}"

Is it intentional or is it a bug?

@wujekbogdan wujekbogdan changed the title Error objects are serialized to {} Error objects are serialized to {} Dec 7, 2021
@SidStraw
Copy link

I have reviewed the code, and currently, only deal with the following types:

RegExp,
Date,
Map,
Set,
Array,
URL,
function,
undefined,
number,
bigint

Error Object was not handled.

If you feel the need, you can try to add it, and I will also try it too.

@okuryu
Copy link
Collaborator

okuryu commented Dec 13, 2021

patches welcome!

@wujekbogdan
Copy link
Author

I guess it happens because Error object properties are not enumerable. There's a lib serialize-error that solves this issue.

SidStraw added a commit to SidStraw/serialize-javascript that referenced this issue Dec 16, 2021
@SidStraw SidStraw linked a pull request Dec 16, 2021 that will close this issue
@SidStraw
Copy link

SidStraw commented Dec 16, 2021

Hello, @okuryu @wujekbogdan

I have added a patch about the support Error object. #136

PTAL, thx.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants