Rethrow Loses Stack Trace (ARCH3154)
Esta página aún no está disponible en tu idioma.
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.
Incorrect
Section titled “Incorrect”async function fetchOrder(id: string): Promise<Order> { try { return await api.get(`/orders/${id}`); } catch (err) { throw new Error("failed to fetch order"); }}Correct
Section titled “Correct”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.