Skip to content

Conversation

@sindresorhus
Copy link
Owner

@sindresorhus sindresorhus commented Sep 8, 2025

Fixes #107 (or rather was already supported)

test.js Outdated
t.is(serialized.cause.code, 8);
// Should preserve DOMException constants
t.is(serialized.cause.NOT_FOUND_ERR, 8);
t.is(serialized.cause.SYNTAX_ERR, 12);
Copy link
Collaborator

@fregante fregante Sep 8, 2025

Choose a reason for hiding this comment

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

This sounds weird, why are these constants serialized? Also I don't see any overlap with the request in #107

It's a static prop:

Screenshot

Docs:

https://webidl.spec.whatwg.org/#idl-DOMException

Copy link
Collaborator

Choose a reason for hiding this comment

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

The issue is in the deserialization since the constructor is an unusual (message, codeString), like new DOMException("Something went wrong", "InvalidStateError"), which serialize-error is not set up to do.

Copy link
Owner Author

Choose a reason for hiding this comment

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

Yeah, I turned the PR into just being about adding a test.

@sindresorhus sindresorhus changed the title Fix DOMException serialization to include error code constants Add tests for DOMException serialization Sep 8, 2025
@sindresorhus sindresorhus merged commit de1ea5c into main Sep 8, 2025
6 checks passed
@sindresorhus sindresorhus deleted the domexception branch September 8, 2025 16:09
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.

serializeError does not deep clone the DOMException when its key name is "cause"

2 participants