Skip to content

Difficult to identify the location of an error of type: SyntaxException: Expected: \|,} at line: 3680 char: 2 #428

Closed

Description

@rdan

Hello,
I am using mako to create a generator of files (.c, .h, ...).
While implementing the templates, I faced the error:
SyntaxException: Expected: \|,} at line: 3680 char: 2.
It took me some time to identify where the issue was.

I finally identified its location:
99: #define EVADC_u32CFG${Cfg_Adc["INDEX"]}_${CfgrdGroup}_CFGD_FADCI_KHz ${CfgrdGroup["FADCI_KHz"]
(there is a missing '}' at the end).

After searching in the code who is reporting this error, I found that "Lexer.parse_until_text()" is.
The difficulty with the exception generated by this function is that it points to a location far far from the source of the problem.
So, I did the following modifications in the function:
1/
I added the following lines at the start of the function:

        startlineno = self.matched_lineno
        startcharpos = self.matched_charpos

2/
I replaced the following code:

            raise exceptions.SyntaxException(
                "Expected: %s" % ",".join(text), **self.exception_kwargs
            )

by:

            self.matched_lineno = startlineno
            self.matched_charpos = startcharpos
            raise exceptions.SyntaxException(
                "Expected '%s' while parsing text starting" % ",".join(text), **self.exception_kwargs
            )

And now, the reported error message is:
SyntaxException: Expected '\|,}' while parsing text starting at line: 99 char: 69

This way, at least I am able to identify the python block or expression that triggered the exception.

I don't know if this is the proper way to reach this goal, but at least I think it would be beneficial for every user of mako to be able to identify the python block/expression in which an error has been detected.

Ronan

Activity

  1. zzzeek commented on Sep 19, 2025

    @zzzeek
    Member

    we accept pull requests for simple fixes like this.

  2. sqla-tester commented on Aug 4, 2026

    @sqla-tester
    Collaborator

    Mike Bayer has proposed a fix for this issue in the main branch:

    Report the start of an unterminated tag or expression https://gerrit.sqlalchemy.org/c/sqlalchemy/mako/+/6866

  3. added a commit that references this issue on Aug 4, 2026
    717e18e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions