sindresorhus/serialize-error

Optionally preserve current stack

Chiusa

#98 aperta il 25 set 2024

 (6 commenti) (0 reazioni) (0 assegnatari)JavaScript (69 fork)user submission
enhancementhelp wanted

Metriche repository

Star
 (599 stelle)
Metriche merge PR
 (Nessuna PR mergiata in 30 g)

Descrizione

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});

Guida contributor