Empty exception handler

Empty exception handler

Description

A catch block that ignores an error or only logs it can leave the caller unaware that the operation failed.

Potential impact

Processing may continue after a file operation, authentication check or cryptographic check fails.

Remediation

Handle a recoverable error with an explicit recovery action. Otherwise return a failure or rethrow the error. Redact sensitive log values and restrict access to the logs.

Examples

Before

javascript
try {
  verifySignature(input);
} catch (err) {
}

After

javascript
try {
  verifySignature(input);
} catch (err) {
  logger.error({ err }, "signature verification failed");
  throw err;
}

If verifySignature throws, the revised catch logs the error. throw err then passes it to the caller.

References