Skip to content

fix: report E0002 from rule collections that do not register RuleError - #4908

Merged
kddejong merged 1 commit into
aws-cloudformation:mainfrom
hoganbr-amzn:fix/e0002-unregistered-rule-error
Oct 30, 2026
Merged

kddejong merged 1 commit into
aws-cloudformation:mainfrom
hoganbr-amzn:fix/e0002-unregistered-rule-error

Conversation

@hoganbr-amzn

@hoganbr-amzn hoganbr-amzn commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Issue #, if available: fixes #4948

Description of changes:

Rules.run_check turns an exception raised by a rule into an E0002 match whenever RuleError is enabled by the configuration. Rules.run then passes every match through _filter_matches, which only lets through ids that are in the collection's own enabled_rule_ids. A collection built without RuleError registered (api.lint(rules=...), or any --append-rules user who builds a Rules by hand) therefore drops the E0002 and a crashing rule produces no output at all.

The fix adds E0002 to enabled_rule_ids when RuleError is enabled, which is the same test run_check already makes. The CLI is unaffected because it loads cfnlint.rules, which includes RuleError.

Repro on main:

from cfnlint import ConfigMixIn, Template
from cfnlint.rules import CloudFormationLintRule, Rules

class Boom(CloudFormationLintRule):
    id = "E9999"; shortdesc = description = "boom"
    def match(self, cfn):
        raise RuntimeError("boom")

rules = Rules(); rules.register(Boom())
print(list(rules.run("-", Template("-", {}, ["us-east-1"]), ConfigMixIn([]))))
# []            before
# [E0002 ...]   after

Tests: test_rule_failure_without_rule_error_registered (red on the parent, green on the fix) and test_rule_failure_respects_ignore_of_rule_error (an --ignore-checks E0002 still suppresses it).

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Rules.run_check emits an E0002 match for a rule that raises, but
_filter_matches only passes ids that are in the collection, so a rule
crash in a collection built without RuleError (api.lint(rules=...),
append-rules users) disappeared. Add E0002 to the enabled set when it is
enabled by the configuration, which is what run_check already checks.

Signed-off-by: Brenden Hogan <hoganbr@amazon.com>
@kddejong
kddejong force-pushed the fix/e0002-unregistered-rule-error branch from a8fd20f to 2f21e05 Compare October 30, 2026 20:27
@codecov

codecov Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.72%. Comparing base (008ead6) to head (2f21e05).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4908   +/-   ##
=======================================
  Coverage   94.71%   94.72%           
=======================================
  Files         442      442           
  Lines       16087    16089    +2     
  Branches     3120     3121    +1     
=======================================
+ Hits        15237    15240    +3     
  Misses        468      468           
+ Partials      382      381    -1     
Flag Coverage Δ
unittests 94.71% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@kddejong
kddejong merged commit 3c581cf into aws-cloudformation:main Oct 30, 2026
24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Regression in 1.39.0: a rule that raises inside a Rules collection without RuleError registered no longer produces E0002

2 participants