question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error subclasses are lost when deserializing

See original GitHub issue
const {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:closed
  • Created 2 years ago
  • Reactions:3
  • Comments:7 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
sindresorhuscommented, Mar 20, 2022

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 with Set. It’s the correct data structure for this.

0reactions
fregantecommented, Oct 9, 2022

You can open a new issue. Given it’s a complex error, it first needs proper serialization support.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found