redline
MediumError handlingmatch-error-message

Branches on error text

Branches on error text. Decides what to do by reading the error's message text.

This is how the comment reads inline, under the flagged line.

Why it matters

Error messages are for people and change without notice. A reworded message silently changes control flow.

What to do

Check the error type or code (instanceof, err.code, a specific exception class).

Examples

Flagged
if (err.message.includes("timeout")) retry();
Better
if (err instanceof TimeoutError) retry();

What it catches

It reads a pattern on each line, aware of strings and comments. Languages: TypeScript and JavaScript, Python. Scope: All files. These cases are the rule's own tests: the first set must be flagged and the second must not.

Flagged

if (err.message.includes("timeout")) retry();
src/app.py
if 'timeout' in str(e):
    pass

Left alone

if (err instanceof TimeoutError) retry();

Research

Branching on an error's message text. The branch flips silently when the wording changes.

Turn it off or change it

In a config file for the CLI, or in the API's rules field:

{
  "rules": {
    "disable": [
      "match-error-message"
    ],
    "severity": {
      "match-error-message": "low"
    }
  }
}

Read the source or report a false positive.