Skip to content

Narrow Json error types#1637

Open
thewilkybarkid wants to merge 2 commits into
gcanti:masterfrom
thewilkybarkid:json-error-types
Open

Narrow Json error types#1637
thewilkybarkid wants to merge 2 commits into
gcanti:masterfrom
thewilkybarkid:json-error-types

Conversation

@thewilkybarkid

Copy link
Copy Markdown
Contributor

JSON.parse and JSON.stringify only throw SyntaxError and TypeError respectively, so we can narrow the types in the Json module.

There is one custom error in stringify, but this is better represented as a TypeError anyway.

@enricopolanski

Copy link
Copy Markdown

I like the proposal, I think though that we are missing a case?

JSON.stringify({x: 2n});
// TypeError: BigInt value can't be serialized in JSON

Should we handle both the TypeErrors messages rather than only cyclic references?

@thewilkybarkid

Copy link
Copy Markdown
Contributor Author

Having tried this out for a bit, these types are a bit problematic: TypeError and SyntaxError are just aliases of Error.

So, I'd probably say to create new error types, or just use Error (which is better than the original unknown).

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.

2 participants