Closed arschles closed 6 years ago
The first line is telling you what the problem is:
jobs.html: jobs: unknown identifier
you are reference a variable, or function, named jobs
that isn't on the context.
The problem with the stack trace is that Go doesn't actually give you stack traces, so we use a package called github.com/pkg/errors
to generate a stack trace. Sometimes it's good and helpful, sometimes not so much. Unfortunately it's one of the big down sides of go. :(
Yep, makes sense. I think I didn't explain well -- I was more referring to the lack of information to help developers debug their templates.
Let me give some better examples.
%>
Given this template:
<!DOCTYPE html>
<html lang="en-us">
<head>
<%= if (true) {
<title>Hello buffalo!</title>
<% } %>
</head>
</html>
The renderer will panic because the if
doesn't have a closing %>
. In this particular case, the plush parser looks to be the culprit. I think here, it would be more helpful to indicate that there's a missing closing %>
and print the line number.
In renderer terms, the heuristic might be to record the line break token and, if there's a syntax error (or nil pointer as seems to be the case here), tell the user something like "we got a syntax error, did you maybe forget to add a closing %>
on line X?"
If you forget to add an opening or closing curly brace ({
or }
):
<!DOCTYPE html>
<html lang="en-us">
<head>
<%= if (true) %>
<title>Hello buffalo!</title>
<% } %>
</head>
</html>
Then you get a stack trace and a descriptive error message:
file.html: expected next token to be {, got %> instead
If the file is not complex (1-2 block-level statements), I believe these messages are just fine, but as the template gets more complex, I think it's a lot harder to figure out where the error is. For me, a line number along with the file name would be extremely helpful.
I hope this doesn't come off as me saying there's something wrong with plush, the template syntax, or something else. A huge :100: from me on all things buffalo templating. This change is just a bit to give developers a little more ease of use.
And if you think this is a reasonable way to go, I'm happy to take a crack at these changes in plush.
Thoughts?
I did just commit this, https://github.com/gobuffalo/plush/pull/26/commits/c2c634d757d1b98674eaf58bcf0d346a23bedecb, which adds line numbers to the error message, which should go a long way to address.
If you've got ideas on improving it, please open a PR. I would love to see better, and clearer, error messages come out of Plush.
https://www.evernote.com/l/ABE9Toh7M4dCuIYkWsZVPz1tLHbQhBg9spU
Line numbers FTW indeed 😄
I'll put together some repro steps for the panic when I get a minute, and submit a PR to plush for it.
If a template has an error in it, you get a slightly-ambiguous error message and a stack trace. For example:
I actually still have not tracked down this issue, but I think I forgot a closing
}
somewhere.Is there a "dev" flag I can pass to the renderer or parser?
(I wasn't sure where to file this issue -- here or in https://github.com/gobuffalo/plush. If I put this in the wrong place, I'm happy to re-file it over there.)
Thanks!