Error subclasses are lost when deserializing
See original GitHub issueconst {serializeError, deserializeError} = require('serialize-error');
class MyError extends Error {
constructor(message) {
super(message);
this.name = 'MyError'
}
}
const original = new MyError('This is my error');
const serialized = serializeError(original);
const deserialized = deserializeError(serialized);
original
will be a MyError
but deserialized
will be a plain Error
Live example: https://runkit.com/embed/f46ewcgxyxqg
I think deserializeError
should support custom error types, if passed as an argument (so they are known and explicit):
const deserialized = deserializeError(serialized, {constructors: [MyError, BusinessError, ErrorError]});
Native errors also should be automatically supported, like TypeError
Issue Analytics
- State:
- Created 2 years ago
- Reactions:3
- Comments:7 (6 by maintainers)
Top Results From Across the Web
c# - Deserializing to a subclass problems - Stack Overflow
I have been trying to deserialize some XML into a class which is a subclass of another class. When I tried deserializing into...
Read more >Subclasses won't deserialize types in superclass #210 - GitHub
Correct. The biggest problem is if the inner class has functions. For example, if FooMoney had methods like add() or subtract() ...
Read more >constructor to deserialize not found error for classes dervied ...
Hi, I have tried quite a bit of searching and don't appear to come across anything that is equivalent to this problem. The...
Read more >Inheritance in Jackson | Baeldung
This tutorial will demonstrate how to handle inclusion of subtype metadata and ignoring properties inherited from superclasses with Jackson.
Read more >Definitive Guide to Jackson ObjectMapper - Serialize and ...
Now both when serializing and deserializing, the snake case would be ... However, there are 19 sub-classes of JsonNode we can use to...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Sure. I don’t think it should contain the built-in error types though. We don’t want users to be able to remove those. So maybe it should be named
customErrorClasses
? I would go withSet
. It’s the correct data structure for this.You can open a new issue. Given it’s a complex error, it first needs proper serialization support.