A catch block ignores the error without saying why

tx0/ts:empty-catchrecommendedwarningsmell, cwe-390

What it finds

try { save(); } catch (e) {}: an empty catch swallows every error of the try block, including the ones nobody expected, and the program goes on as if nothing had happened.

A comment inside the block, saying why the error does not matter, marks the silence as deliberate and keeps the rule quiet.

From the rule's source, empty_catch.rs.

Example from the rule's tests
function parse(text: string) {  try {    return JSON.parse(text);  } catch (e) {}tx0 reports: this catch block ignores the error  try {    return JSON.parse(text);  } catch { /* invalid input is fine here */ }  try {    return JSON.parse(text);  } catch (e) {    return null;  }}
Highlighted lines are the ones tx0 reports, with its message under each; the other lines are left alone.

Turn it on, off or suppress it

The rule runs from the recommended tier up. To turn it on in a lower tier, give it a level in tx0.toml:

tx0.toml
[rules]
"tx0/ts:empty-catch" = "warning"

To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:

// tx0: ignore[tx0/ts:empty-catch] reason="..."

tx0 explain tx0/ts:empty-catch shows the same in the terminal. Found a false positive? Report it.