Skip to content

fix(rules): stringify E3601 path segments so array indices do not crash message formatting - #4782

Merged
kddejong merged 1 commit into
aws-cloudformation:mainfrom
Varshith-Kali:fix-4775-e3601-array-path-crash
Oct 21, 2026
Merged

kddejong merged 1 commit into
aws-cloudformation:mainfrom
Varshith-Kali:fix-4775-e3601-array-path-crash

Conversation

@Varshith-Kali

Copy link
Copy Markdown
Contributor

Summary

Fixes #4775.

When a Step Functions DefinitionString contains a validation error whose path crosses a JSON array (for example an ErrorEquals type error inside a Catch entry), E3601's _fix_message crashed and the cfn-lint dispatcher reported it as E1101. Worse, every other E3601 finding on that state machine was silently lost with the crash: a template with three real errors reported only the E1101.

Root cause

In src/cfnlint/rules/resources/stepfunctions/StateMachineDefinition.py, _fix_message built the message suffix with '/'.join(err.path). err.path is a jsonschema deque that holds integer indices for array positions, so the join raised TypeError: sequence item 3: expected str instance, int found for any path like States/T/Catch/0/ErrorEquals. This only affected the string form, because _fix_message runs only when the definition was parsed from DefinitionString (add_path_to_message=True).

Fix

Stringify each path element before joining: '/'.join(str(p) for p in err.path). Integer indices now render literally, so the suffix reads at 'States/T/Catch/0/ErrorEquals' and all findings surface as E3601.

Tests

  • New regression test test_fix_message_with_array_index_in_path in test/unit/rules/resources/stepfunctions/test_state_machine_definition.py: a JSON-string DefinitionString with the issue's template-B shape (error inside Catch[0] plus a bad StartAt and an invalid state Type). It asserts all three E3601 findings surface, the path suffix renders with the array index, and no E1101 appears. Red/green verified: the test fails with TypeError on the unpatched code and passes with the fix.
  • Full stepfunctions rule suite: 21/21 pass. ruff check and ruff format clean on both changed files.
  • End-to-end check with the CLI on the issue's repro templates A and B: A reports E3601 'States.ALL' is not of type 'array' at 'States/T/Catch/0/ErrorEquals'; B reports that error plus the two previously hidden findings (StartAt target, invalid state Type); no E1101.

Known limits

None beyond the pre-existing behavior: message suffixes were already best-effort path annotations for the string form. The object form (Definition) was never affected and is unchanged.

…sh message formatting

E3601's _fix_message joined err.path with '/'.join(err.path), but err.path
is a jsonschema deque that holds integer indices when the error sits inside
an array (for example a Catch entry at States/T/Catch/0/ErrorEquals).
The join raised TypeError, which the dispatcher reported as E1101, and every
other E3601 finding on the same state machine was lost.

Stringify each path element before joining, so integer indices render as
'States/T/Catch/0/ErrorEquals' and all findings surface as E3601.

Adds a regression test covering an error inside Catch[0] in a JSON-string
DefinitionString (fails with TypeError before the fix).

Fixes aws-cloudformation#4775

Signed-off-by: Varshith Puli <pulivarshit@gmail.com>
@kddejong
kddejong force-pushed the fix-4775-e3601-array-path-crash branch from ee2595f to dbab1cb Compare October 21, 2026 00:01
@codecov

codecov Bot commented Oct 21, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.70%. Comparing base (16acc6f) to head (dbab1cb).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4782   +/-   ##
=======================================
  Coverage   94.70%   94.70%           
=======================================
  Files         439      439           
  Lines       15895    15895           
  Branches     3078     3078           
=======================================
  Hits        15053    15053           
  Misses        459      459           
  Partials      383      383           
Flag Coverage Δ
unittests 94.70% <100.00%> (ø)

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 27243cb into aws-cloudformation:main Oct 21, 2026
21 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.

E3601 crashes (reported as E1101) when an error in a JSON-string DefinitionString sits under an array item

2 participants