Skip to main content
ai-slop/python-bare-exceptmanual fix

Bare except.

An `except:` clause with no exception type. It catches everything, including `KeyboardInterrupt` and `SystemExit`, so Ctrl-C and clean shutdowns are swallowed along with the real bugs.

Flagged shape and clean shape.

Each example shows the exact code shape the rule is looking for, then the smallest version that keeps the intent without hiding risk or adding noise.

python-bare-except.py
✗ Flagged
def load_config(path):
    try:
        with open(path) as handle:
            return json.load(handle)
    except:
        return {}
Why this trips

Deterministic line match: flags any `except:` line with no exception class (optionally followed by a comment) in non-test Python files.

python-bare-except.py
✓ Clean
def load_config(path):
    try:
        with open(path) as handle:
            return json.load(handle)
    except FileNotFoundError:
        return {}
    except json.JSONDecodeError as error:
        raise ConfigError(f"invalid config at {path}") from error
What changed

Catch the specific exception you expect. If you genuinely need everything, write `except BaseException:` and re-raise or log, so the intent is explicit.

Agents wrap uncertain calls in try/except to make a snippet run, and the shortest form that silences every error is `except:`. It reads as defensive; it hides which failure the code was meant to survive.

How this rule is justified.

Rule id

ai-slop/python-bare-except

Enforcing engine

ai-slop

Detector strategy

Deterministic line match: flags any `except:` line with no exception class (optionally followed by a comment) in non-test Python files.

Legitimate code that is NOT flagged

Typed handlers such as `except ValueError:` or `except (KeyError, IndexError):`, and test files, are not flagged. The rule fires on the clause itself, whatever the body does.

Evidence

Part of aislop's Python rule set, scored in the strict tier because a bare except catches system exits and hides real failures.