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

Optionally ignore toJSON #66

Closed
fregante opened this issue Mar 31, 2022 · 2 comments · Fixed by #71
Closed

Optionally ignore toJSON #66

fregante opened this issue Mar 31, 2022 · 2 comments · Fixed by #71

Comments

@fregante
Copy link
Contributor

serialize-error automatically uses toJSON:

serialize-error/index.js

Lines 61 to 63 in 855fe3d

if (typeof from.toJSON === 'function' && from[toJsonWasCalled] !== true) {
return toJSON(from);
}

Unfortunately this introduces two unwanted behaviors:

  • code can be executed by passing {toJSON() { /*h4xor*/ }}
  • serialization is decided by the object owner, with which we might disagree (e.g. it might exclude arbitrary properties)

Possible solution

serializeError(error, {toJSON: false})
@sindresorhus
Copy link
Owner

code can be executed by passing {toJSON() { /h4xor/ }}

This is not a good argument. This applies to built-in APIs too. And also .toString().

serialization is decided by the object owner, with which we might disagree (e.g. it might exclude arbitrary properties)

This is a valid argument.

@sindresorhus
Copy link
Owner

I'm ok with a toJSON option.

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

Successfully merging a pull request may close this issue.

2 participants