Skip to content

Fix TypeError when reporting ParseSyntaxError in parse_fortran_var_decl#726

Open
jimmielin wants to merge 2 commits intoNCAR:developfrom
jimmielin:hplin/parse_error
Open

Fix TypeError when reporting ParseSyntaxError in parse_fortran_var_decl#726
jimmielin wants to merge 2 commits intoNCAR:developfrom
jimmielin:hplin/parse_error

Conversation

@jimmielin
Copy link
Contributor

[ 50 character, one line summary ]
Fix TypeError from ParseSyntaxError in parse_fortran_var_decl

[ Description of the changes in this commit. It should be enough
information for someone not following this development to understand.
Lines should be wrapped at about 72 characters. ]
In parse_fortran_var_decl(), when FortranVar() raises a
ParseSyntaxError, the exception object was appended directly
to the errors list. parse_module expects string elements and calls
'\n'.join(errors), which crashes with a TypeError. Convert
the exception to a string before appending.

From the context above errmsg is already being appended to
errors array so I think this is a safe change to make that is
consistent with the intended type of errors[].

User interface changes?: No

Fixes: closes #725

Testing:
test removed:
unit tests:
system tests:
manual testing: see minimal reproducible example in issue #725

@jimmielin jimmielin requested review from a team and gold2718 as code owners March 15, 2026 22:24
Copy link
Collaborator

@nusbaume nusbaume left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The source code change looks good to me, but should we add some sort of doctest or unit test to ensure that the error you ran into will continue to be caught correctly in the future?

@jimmielin
Copy link
Contributor Author

Thanks @nusbaume for the suggestion, I added a doctest that should cover this change
(the other doctest on the line above it doesn't go to the ParseSyntaxError path so it was not covering this bug)

If the change is not applied, this new test would fail:

702     >>> parse_fortran_var_decl("type(banana_t) :: bananas(0:N_FRUITS)", ParseSource('foo.F90', 'module', ParseContext()), _DUMMY_RUN_ENV)[1][0]
Expected:
    "bananas: '0:N_FRUITS' is an invalid dimension name; integer dimension indices not supported, in <standard input>"
Got:
    ParseSyntaxError("bananas: '0:N_FRUITS' is an invalid dimension name; integer dimension indices not supported, in <standard input>")

Copy link
Collaborator

@nusbaume nusbaume left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the new test @jimmielin! Everything looks good to me now (albeit as a non-framework expert).

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.

TypeError crash in ccpp_fortran_to_metadata.py instead of error message

2 participants