Skip to content

fix(W1040): report resolved Fn::ToJsonString errors under W1040 - #4969

Open
pcbeingused333 wants to merge 1 commit into
aws-cloudformation:mainfrom
pcbeingused333:fix/tojsonstring-w1040
Open

pcbeingused333 wants to merge 1 commit into
aws-cloudformation:mainfrom
pcbeingused333:fix/tojsonstring-w1040

Conversation

@pcbeingused333

Copy link
Copy Markdown
Contributor

Fixes #4961

Root cause

ToJsonString.fn_tojsonstring set err.rule = self on every error yielded by BaseFn.validate. That also overwrote the errors that BaseFn._clean_resolve_errors had already assigned to the W1040 child rule, so resolved-value findings were reported as E1031 (error) with the W1040 message text, --include-checks W1040 had no effect, and --ignore-checks W1040 did not suppress them.

Fix

Only assign self as the rule when the error is not already attached to the resolved-value child rule (W1040).

Test

Added test_resolved_errors_use_w1040: a template with VisibilityTimeout: {Fn::ToJsonString: [1, 2]} now yields a single W1040 instead of E1031. It fails on main and passes with the change; the rest of test/unit/rules/functions and test_rules_collections.py pass.

This PR was prepared with the assistance of an AI coding agent (Claude).

ToJsonString overwrote every error's rule with E1031, including the
resolved-value errors the base class assigns to W1040, so W1040 never
appeared and the findings were reported at error level.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Signed-off-by: Alex Castillo <alex.castillog33@gmail.com>
@pcbeingused333

Copy link
Copy Markdown
Contributor Author

Friendly ping in case this slipped through — happy to adjust anything (scope, tests, style) if that makes review easier. Thanks for maintaining this!

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.

W1040: resolved Fn::ToJsonString value errors are reported under E1031, so W1040 never appears

1 participant