Error handling anti-patterns rules Claude-Mem codebase.

Published: (January 12, 2026 at 10:30 AM EST)
2 min read
Source: Dev.to

Source: Dev.to

Process

  1. Run the detector

    # command to run the detector (example)
  2. Analyze the results

    • Count CRITICAL, HIGH, MEDIUM, and APPROVED_OVERRIDE issues
    • Prioritize CRITICAL issues on critical paths first
    • Group similar patterns together
  3. For each CRITICAL issue

    a. Read the problematic code using the Read tool

    b. Explain the problem

    • Why is this dangerous?
    • What debugging nightmare could this cause?
    • What specific error is being swallowed?

    c. Determine the right fix

    • Option 1: Add proper logging – if this is a real error that should be visible
    • Option 2: Add [APPROVED OVERRIDE] – if this is expected/documented behavior
    • Option 3: Remove the try‑catch entirely – if the error should propagate
    • Option 4: Add specific error type checking – if only certain errors should be caught

    d. Propose the fix and ask for approval

    e. Apply the fix after approval

  4. Work through issues methodically

    • Fix one at a time
    • Re‑run the detector after each batch of fixes
    • Track progress, e.g., “Fixed 3/28 critical issues”

Detect‑error‑handling‑antipatterns script

The script detect-error-handling-antipatterns.ts (≈ 514 LOC) defines several functions for locating anti‑patterns.
In the detectAntiPatterns function, regular expressions are used to spot problematic error handling, for example:

// Example regex patterns
/,\\s(?:error|err|e).message\\s*)/,
{\\s(?:error|err|e):\\s*(?:error|err|e).message\\s*}/,
][^'"]+['"`]\\s*,\\s*(?:error|err|e).message\\s*)/

These patterns are applied like so:

for (const pattern of partialErrorLoggingPatterns) {
  if (pattern.test(trimmed)) {
    if (hasOverride && overrideReason) {
      antiPatterns.push({
        file: relPath,
        line: i + 1,
        // …
      });
    }
  }
}

Another set of patterns:

'"`['"]\\s*\\)/i,
](\\w+)['"]\\s*\\)/i,
](\\w+)['"`]\\s*)/i,

Regex vs. AST

Using an Abstract Syntax Tree (AST) could provide more reliable detection than regex, especially for complex JavaScript code. See the discussion on AST on Stack Overflow.

References

Back to Blog

Related posts

Read more »