sindresorhus/serialize-error

Optionally preserve current stack

Fermée

#98 ouverte le 25 sept. 2024

 (6 commentaires) (0 réaction) (0 personne assignée)JavaScript (69 forks)user submission
enhancementhelp wanted

Métriques du dépôt

Stars
 (599 étoiles)
Métriques de merge PR
 (Aucune PR mergée en 30 j)

Description

An issue I found when throwing deserialized errors is that the thrown error has no reference to this throw point.

I think the "correct" way to throw serialized errors would be something like:

throw new Error(serialized.message, {
	cause: deserializeError(serialized),
});

Two drawbacks:

So how about:

throw deserializeError(serialized, {preserveStack: true});

Guide contributeur