Misleading validation for unclosed tags mixed with html
I wasn't sure if you are accepting bug reports for liquid mixed with html. Anyway, maybe you are interested in fixing this. Let's suppose I forgot to close the variable tag.
> Solid.parse("{{ abc <b>some text</b>")
{:error,
%Solid.TemplateError{
errors: [
%Solid.ParserError{
reason: "Unexpected character '/'",
meta: %{column: 21, line: 1},
text: "{{ abc <b>some text</b>"
}
]
}}
I would expect to receive an error mentioning unclosed tag or something. "/" is definitely correct here as it belongs to the html part.
If I remove the slash I get better error.
Solid.parse("{{ abc <b>text", tags: %{})
{:error,
%Solid.TemplateError{
errors: [
%Solid.ParserError{
reason: "Tag or Object not properly terminated",
meta: %{column: 15, line: 1},
text: "{{ abc <b>text"
}
]
}}
One more note - for unclosed tags the error should use the opening tag line/column ( #165 ). But what if I actually make it happy ?
Solid.parse("{{ abc <b>text }}", tags: %{})
{:error,
%Solid.TemplateError{
errors: [
%Solid.ParserError{
reason: "Unexpected token",
meta: %{column: 8, line: 1},
text: "{{ abc <b>text }}"
}
]
}}
So it has the capacity to detect invalid Liquid syntax but still trying to look for invalid characters in that syntax. In other words, if everything after "abc" is invalid Liquid (in the context of the current tag), the parser should just stop there and report the unclosed tag.
Here is my reasoning for this error:
To me this error says exactly what is the problem with this template:
iex(1)> Solid.parse!("{{ abc <b>text }}")
** (Solid.TemplateError) Unexpected token
1: {{ abc <b>text }}
^
(solid 1.1.0) lib/solid.ex:77: Solid.parse!/2
iex:1: (file)
If I were a new user to Liquid templates and I saw the error reason was: "unclose object" I would think that this is not true as the object is properly closed. The issue is that the < token is not allowed there
Now I agree that it can be slightly confusing that the error below is not complaining about the tag/object not being closed. This happens because we don't accept any character. So first it consumes valid tokens until it finds the closing }}. If an invalid token is found it's erroring out before it reaches the end of the file. I can see an argument that it should accept "anything" until }} is found (or not) and then actually look at the tokens. But I'm not sure this would change a lot the error shown as this character is indeed invalid inside a Liquid object. So it could show two errors: this token is invalid AND the tag/object is not closed?
Solid.parse!("{{ abc <b>some text</b>")
** (Solid.TemplateError) Unexpected character '/'
1: {{ abc <b>some text</b>
^
(solid 1.1.0) lib/solid.ex:77: Solid.parse!/2
iex:1: (file)
I understand where you are coming from - the error is technically correct. But the issue is it's completely useless for the end user - it's unlikely they will find the cause, given reasonably large document (especially if the "unexpected" character is at the end). If we could replace all of that with "unclosed tag found" pointing to the start of the tag that would be a big win for me.