Zum Inhalt springen

Rethrow Loses Stack Trace (ARCH3154)

Dieser Inhalt ist noch nicht in deiner Sprache verfügbar.

Key typescript.logging.rethrow-without-cause · Severity warning · Category logging

Throwing a new error inside a handler without passing the original exception as cause discards the root cause and stack trace. The debugging context is erased entirely.

async function fetchOrder(id: string): Promise<Order> {
try {
return await api.get(`/orders/${id}`);
} catch (err) {
throw new Error("failed to fetch order");
}
}
async function fetchOrder(id: string): Promise<Order> {
try {
return await api.get(`/orders/${id}`);
} catch (err) {
throw new Error("failed to fetch order", { cause: err });
}
}

Pass the original exception via the cause option when throwing the new error.