Pass a derived error in downloadLog

This commit is contained in:
tcely 2026-03-14 19:50:44 -04:00
parent a1d7c45f37
commit 3b562651f9
No known key found for this signature in database
GPG Key ID: 9F1DAF9D9070430F

View File

@ -18,9 +18,12 @@ function downloadLog(
prefix: string = "download-bun", prefix: string = "download-bun",
): void { ): void {
if (error instanceof Error) { if (error instanceof Error) {
// Prepends your context to the error message without losing the Error object properties // Create a new Error so the original isn't mutated
error.message = `${prefix}: ${preface}: ${error.message}`; const derived = new Error(`${prefix}: ${preface}: ${error.message}`, {
f(error); cause: error,
});
derived.stack = error.stack;
f(derived);
} else { } else {
f(`${prefix}: ${preface}: ${String(error)}`); f(`${prefix}: ${preface}: ${String(error)}`);
} }