Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unreachable reached #370

Closed
Keats opened this issue Dec 17, 2018 · 12 comments
Closed

Unreachable reached #370

Keats opened this issue Dec 17, 2018 · 12 comments

Comments

@Keats
Copy link
Owner

Keats commented Dec 17, 2018

From getzola/zola#558

thread 'thread 'thread '<unnamed><unnamed><unnamed>' panicked at '' panicked at 'internal error: entered unreachable code: render_node -> unexpected node: Extends(WS { left: false, right: false }, "layout.html")internal error: entered unreachable code: render_node -> unexpected node: Extends(WS { left: false, right: false }, "layout.html")', ' panicked at '/cargo/registry/src/github.com-1ecc6299db9ec823/tera-0.11.20/src/renderer/processor.rs', :internal error: entered unreachable code: render_node -> unexpected node: Extends(WS { left: false, right: false }, "layout.html")/cargo/registry/src/github.com-1ecc6299db9ec823/tera-0.11.20/src/renderer/processor.rs774', :/cargo/registry/src/github.com-1ecc6299db9ec823/tera-0.11.20/src/renderer/processor.rs:77418::
@Keats
Copy link
Owner Author

Keats commented Dec 18, 2018

So it is trying to render an extends tag, not sure how we ever get there...

@focusaurus

Do you have any memories on the kind of templates that was causing the issue? The parser should not allow extends in a place where it would get rendered and I can't write a template reproducing it.
The easy solution is to remove the unreachable! here but that means we let through bugs.

@focusaurus
Copy link

Oh interesting, yes that makes sense. I am converting a site that uses pug templates and pug templates have an extends keyword. Let me futz around a bit and see if I can reproduce it now that I know what the code was trying to do.

@Keats
Copy link
Owner Author

Keats commented Dec 30, 2018

@focusaurus did you manage to reproduce it?

@focusaurus
Copy link

Presumably it was something related to {% extends "layout.html" %} which I do use in my templates, but I can't reproduce it.

@Keats
Copy link
Owner Author

Keats commented Jan 2, 2019

Yes, definitely related to an extends like that. The issue is that the parser probably allows it at a place it shouldn't be allowed.

@sbstp
Copy link

sbstp commented Jan 14, 2019

I'm getting an issue similar to this

{% macro path_item(path) %}
    <span class="path" title="{{ path.path }}">{{ path.filename }}</span>
{% endmacro path_item %}

...

<td>{{ self::path_item(path=match.info.path) }}</td>
thread 'main' panicked at 'internal error: entered unreachable code: render_node -> unexpected node: MacroDefinition(WS { left: false, right: false }, MacroDefinition { name: "path_item", args: {"path": None}, body: [Text("\n        <span class=\"path\" title=\""), VariableBlock(Expr { val: Ident("path.path"), negated: false, filters: [] }), Text("\">"), VariableBlock(Expr { val: Ident("path.filename"), negated: false, filters: [] }), Text("</span>\n    ")] }, WS { left: false, right: false })', /home/simon/.cargo/registry/src/github.com-1ecc6299db9ec823/tera-0.11.20/src/renderer/processor.rs:774:18```

@sbstp
Copy link

sbstp commented Jan 14, 2019

Ah sorry to have bothered you. I believe the issue is in this little sentence: "Macros currently need to be defined in a separate file and imported to be useable."

@Keats
Copy link
Owner Author

Keats commented Jan 14, 2019

that's still a panic that should be fixed! Thanks for the report

@Keats
Copy link
Owner Author

Keats commented Jan 17, 2019

I added a failing test for that @sbstp on the v1 branch.
Fixing it at the rendering phase is easy but I need to think whether we can error on that at parsing time instead which would be nicer.

@sbstp
Copy link

sbstp commented Jan 17, 2019

Are macros limited to being in a standalone file because of some technical reason?

@Keats
Copy link
Owner Author

Keats commented Jan 18, 2019

I don't remember exactly, I think that the issue with being in the same file is that the file was usually to be rendered so the macro could have been defined in a forloop or something similar and it currently only checks the top level of a template for macro definitions. It could be allowed by searching recursively in the AST but now I kind of like macros being separated from actual templates.

@focusaurus
Copy link

Thank you for the fix! 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants