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

Expect a message property at a minimum to be interpreted as an Error #77

Merged
merged 6 commits into from May 12, 2022

Conversation

fregante
Copy link
Contributor

@fregante fregante commented May 9, 2022

No description provided.

Comment on lines 182 to -196
test('should deserialize error', t => {
const deserialized = deserializeError(new Error('test'));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test was not testing deserialization

test('should deserialize error', t => {
const deserialized = deserializeError(new Error('test'));
const deserialized = deserializeError({
message: 'Stuff happened',
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the new minimum viable serialized object

@@ -169,10 +169,23 @@ test('should deserialize array', t => {
deserializeNonError(t, [1]);
});

test('should deserialize empty object', t => {
deserializeNonError(t, {});
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

serializeError({}) was deserialized as new Error(''), now it throws a NonError

index.js Outdated
@@ -78,7 +78,7 @@ const destroyCircular = ({
from: value,
seen: [...seen],

to_: isErrorLike(value) ? new Error() : undefined,
to_: isMinimumViableSerializedError(value) ? new Error() : undefined,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fixes the inconsistent expectation between the minimum viable error at the top level and for nested errors.

  • {} was deserialized as an error
  • {cause: {name: 'Error', message: 'foo'} was serialized as an error, but cause wasn't

After #73 this check should also be changed in the new code there.

@fregante fregante changed the title Test deserialization in tests Expect a message property at a minimum to be interpreted as an Error May 9, 2022
index.js Outdated Show resolved Hide resolved
@sindresorhus
Copy link
Owner

I think the docs should explicitly mention what we consider an error when deserializing: https://github.com/sindresorhus/serialize-error#deserializeerrorvalue-options

@fregante
Copy link
Contributor Author

fregante commented May 11, 2022

By the way this is another breaking change, technically, because:

  deserializeError({stuffHappened: "details"})
- // => new Error('') with 'stuffHappened' property
+ // => new NonError('{"stuffHappened": "details"}')

@sindresorhus
Copy link
Owner

Can you fix the merge conflict?

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 this pull request may close these issues.

None yet

2 participants