This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Coerces an unknown value into an Error type if it is not an instance of | |
* Error. The original unknown value is still accessible as the cause of the | |
* coerced error. | |
*/ | |
function coerceToError(thrown: unknown) { | |
if (thrown instanceof Error) return thrown; | |
return new Error("COERCED_NON_ERROR_VALUE", { cause: thrown }); | |
} |