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

Enumerable properties are made non-enumerable #84

Closed
MikeJerred opened this issue Mar 15, 2023 · 2 comments · Fixed by #102
Closed

Enumerable properties are made non-enumerable #84

MikeJerred opened this issue Mar 15, 2023 · 2 comments · Fixed by #102

Comments

@MikeJerred
Copy link

Enumerable properties are made non-enumerable after deserialization.

import { deserializeError, serializeError } from 'serialize-error';

class MyError extends Error {
  constructor(public params: any) {
    super('test');
  }
}

const error = new MyError({ name: 'foo' });
const serialized = serializeError(error);
const deserialized = deserializeError(serialized) as MyError;

// properties of deserialized.params are non-enumerable

Minimal reproduction: https://stackblitz.com/edit/typescript-dkbp39?file=index.ts

@twschiller
Copy link

twschiller commented Jan 3, 2025

➕ We came across this also with a nested property named message. Perhaps related to names that are Error instance properties?

Update: it looks like it's the list here: https://github.com/sindresorhus/serialize-error/blob/main/index.js#L19

@fregante
Copy link
Collaborator

fregante commented Jan 3, 2025

When serializing, this metadata is lost, so the module just renders those known properties non-enumerable as defined in that list. I'm not sure why that happens for params though, it might be the default.

Additionally in @twschiller's case, the object is being deserialized as an error when it isn't, because of this loose check:

export function isErrorLike(value) {

In this specific case the fix would be to specific type obj.message === 'string'. I will send a PR today.

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.

4 participants