Skip to content

duplicate-adjacent-exception-handler

Adjacent exception handlers repeat the same executable translation.

Why

Repeating one translation for adjacent statically known exception classes creates extra branches to maintain without different behavior.

Fix

Consider one tuple handler for the adjacent exception types. Preserve distinct messages, cleanup, ordering, and intentional independently maintained translations.

Examples

Before — flagged Adjacent handlers translate identically
app/service.py
try:
action()
except ValueError as error:
raise RuntimeError("invalid") from error
except TypeError as error:
raise RuntimeError("invalid") from error
After — preferred One handler owns the shared translation
app/service.py
try:
action()
except (ValueError, TypeError) as error:
raise RuntimeError("invalid") from error