jgm/doctemplates

Misleading error message for unmatched template conditionals

tstenner opened this issue · 8 comments

In pandoc 2.5, a template with an unmatched template conditional causes pandoc to fail with an error:

$ cat test.md 
Foo.
$endif$

$ echo 'Test' | pandoc --template=test.md
[WARNING] This document format requires a nonempty [...]
"template" (line 2, column 7):
unexpected "$"

Any non-keyword (e.g. $endi$) is replaced by an empty string and a document is created. While the error message indicates the correct position, it should also include the keyword, i.e. "template" (line 2, column 7): unexpected "$else$"

jgm commented

Right, I see. Could you move this issue to jgm/doctemplates or should I open a new issue?

jgm commented
jgm commented

Note: no document is created. Try -o test.out; you'll see there is no test.out.

So you're getting an error message about invalid syntax in the template, which points to the line and column where the error is. All this is just right. The only thing that could be improved, as far as I can see, is that it could say unexpected "$endif$" instead of unexpected "$". Am I missing something?

The only thing that could be improved, as far as I can see, is that it could say unexpected "$endif$" instead of unexpected "$"

That's correct. It's great the correct location is indicated, but if the error message indicated that a $ would be allowed, just not a lone $endif$ it'd be easier to correct the mistake in the template.

jgm commented

Well, actually a lone $ would not be allowed.

You're right, but a single $ also has a good error message:

$endif$
      ^    -> error: unexpected "$"
      ^       maybe "error: $endif$ without $if$"?

$endi$        Ok, evaluates to empty string

Test $foo without closing dollar sign
         ^    -> error: unexpected " ", expecting "." or "$"
jgm commented

Yes, I agree that the messages could be somewhat better.
This is a low priority for me, though, compared to other things.
I'll move this to doctemplates and perhaps someone will take it up.