Skip to content

Commit

Permalink
Improve error messages for inconsistent identifiers
Browse files Browse the repository at this point in the history
Ref. eng/recordflux/RecordFlux!1673
  • Loading branch information
treiher committed Sep 11, 2024
1 parent b8dfd55 commit 80db1d7
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
26 changes: 19 additions & 7 deletions rflx/specification/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,17 +226,22 @@ def create_state(
package: ID,
filename: Path,
) -> model.State:
location = node_location(state, filename)
identifier = create_id(error, state.f_identifier, filename)
assert isinstance(state.f_body, lang.StateBody)
if state.f_identifier.text != state.f_body.f_end_identifier.text:
error.extend(
[
ErrorEntry(
"inconsistent state identifier: "
f"{state.f_identifier.text} /= {state.f_body.f_end_identifier.text}",
f'inconsistent state identifier "{state.f_body.f_end_identifier.text}"',
Severity.ERROR,
location,
node_location(state.f_body.f_end_identifier, filename),
[
Annotation(
f'previous identifier was "{identifier}"',
Severity.NOTE,
node_location(state.f_identifier, filename),
),
],
),
],
)
Expand Down Expand Up @@ -274,10 +279,17 @@ def _check_state_machine_identifier(
error.extend(
[
ErrorEntry(
"inconsistent state machine identifier: "
f"{state_machine.f_identifier.text} /= {state_machine.f_end_identifier.text}",
"inconsistent state machine identifier"
f' "{state_machine.f_end_identifier.text}"',
Severity.ERROR,
node_location(state_machine, filename),
node_location(state_machine.f_end_identifier, filename),
[
Annotation(
f'previous identifier was "{state_machine.f_identifier.text}"',
Severity.NOTE,
node_location(state_machine.f_identifier, filename),
),
],
),
],
)
Expand Down
8 changes: 6 additions & 2 deletions tests/unit/specification/parser_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4769,7 +4769,10 @@ def test_state_error() -> None:
goto B
end C
"""
error = "<stdin>:2:8: error: inconsistent state identifier: A /= C.*"
error = (
r'<stdin>:6:12: error: inconsistent state identifier "C"\n'
r'<stdin>:2:14: note: previous identifier was "A"'
)
with pytest.raises(RecordFluxError, match=rf"^{error}$"):
parse_state(string)

Expand Down Expand Up @@ -4853,7 +4856,8 @@ def test_parse_state_machine() -> None:
end A;
end Y
""",
"<stdin>:2:16: error: inconsistent state machine identifier: X /= Y.*",
r'<stdin>:10:20: error: inconsistent state machine identifier "Y"\n'
r'<stdin>:3:24: note: previous identifier was "X"',
),
(
"""
Expand Down

0 comments on commit 80db1d7

Please sign in to comment.