Catch Without Log Or Rethrow (ARCH3165)
Dieser Inhalt ist noch nicht in deiner Sprache verfügbar.
Key typescript.logging.catch-log-only · Severity info · Category logging
A handler that catches and logs an exception but then continues normal flow without rethrowing may be swallowing the error unintentionally. Log-only handling of an unrecoverable error is dangerous.
Incorrect
Section titled “Incorrect”async function chargeCard(payment: Payment) { try { await gateway.charge(payment); } catch (err) { logger.error("payment failed", { err }); } await markComplete(payment); // marked complete despite the failure}Correct
Section titled “Correct”async function chargeCard(payment: Payment) { try { await gateway.charge(payment); } catch (err) { logger.error("payment failed", { err }); throw err; } await markComplete(payment);}Rethrow the exception after logging unless the recovery is intentional.