doctemplates icon indicating copy to clipboard operation
doctemplates copied to clipboard

Misleading error message for unmatched template conditionals

Open tstenner opened this issue 5 years ago • 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$"

tstenner avatar Jan 14 '19 08:01 tstenner

jgm/doctemplates is the library used for parsing templates, so any improvements would need to go there.

jgm avatar Jan 14 '19 20:01 jgm

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

tstenner avatar Jan 15 '19 12:01 tstenner

I can move it...

jgm avatar Jan 15 '19 22:01 jgm

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?

jgm avatar Jan 18 '19 00:01 jgm

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.

tstenner avatar Jan 24 '19 08:01 tstenner

Tristan Stenner [email protected] writes:

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.

Well, actually a lone $ would not be allowed. Literal $ must be escaped as $$.

jgm avatar Jan 24 '19 22:01 jgm

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 "$"

tstenner avatar Jan 25 '19 09:01 tstenner

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.

jgm avatar Jan 25 '19 23:01 jgm