yahoo / serialize-javascript

Serialize JavaScript to a superset of JSON that includes regular expressions and functions.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`Error` objects are serialized to `{}`

wujekbogdan opened this issue · comments

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?

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.

patches welcome!

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

Hello, @okuryu @wujekbogdan

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

PTAL, thx.