Ir al contenido

Catch Without Log Or Rethrow (ARCH3165)

Esta página aún no está disponible en tu idioma.

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.

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
}
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.