Skip to content

Commit

Permalink
Improved the Handling of Errors in Rule Collection (#479)
Browse files Browse the repository at this point in the history
* Added try catch to gracefully handle errors when importing rules

* Changed log.error to log.warning

* Handle generic errors

* Updated warning message
  • Loading branch information
surge119 authored Aug 10, 2024
1 parent e4d9bbd commit dfd84cb
Showing 1 changed file with 22 additions and 12 deletions.
34 changes: 22 additions & 12 deletions src/fixit/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,20 +226,30 @@ def collect_rules(
stack.enter_context(append_sys_path(path))

for qualified_rule in config.enable:
rules = set(find_rules(qualified_rule))
if qualified_rule.name:
named_enables |= rules
all_rules |= rules
try:
rules = set(find_rules(qualified_rule))
if qualified_rule.name:
named_enables |= rules
all_rules |= rules
except Exception as e:
log.warning(
f"Failed to load rules '{qualified_rule.module}': {e.__class__.__name__}: {e}"
)

for qualified_rule in config.disable:
disabled_rules.update(
{
r: "disabled"
for r in find_rules(qualified_rule)
if r not in named_enables
}
)
all_rules -= set(disabled_rules)
try:
disabled_rules.update(
{
r: "disabled"
for r in find_rules(qualified_rule)
if r not in named_enables
}
)
all_rules -= set(disabled_rules)
except Exception as e:
log.warning(
f"Failed to load rules '{qualified_rule.module}': {e.__class__.__name__}: {e}"
)

if config.tags:
disabled_rules.update(
Expand Down

0 comments on commit dfd84cb

Please sign in to comment.