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

Report unsupport tags/filters more nicely #220

Closed
jvanzyl opened this issue Aug 20, 2021 · 7 comments
Closed

Report unsupport tags/filters more nicely #220

jvanzyl opened this issue Aug 20, 2021 · 7 comments

Comments

@jvanzyl
Copy link
Collaborator

jvanzyl commented Aug 20, 2021

Right now it's really hard to tell during parsing when a tag/filter is not implemented. You just get a NPE:

java.lang.NullPointerException
	at liqp.nodes.TagNode.<init>(TagNode.java:22)
	at liqp.parser.v4.NodeVisitor.visitOther_tag(NodeVisitor.java:104)
	at liqp.parser.v4.NodeVisitor.visitOther_tag(NodeVisitor.java:24)
	at liquid.parser.v4.LiquidParser$Other_tagContext.accept(LiquidParser.java:588)
	at org.antlr.v4.runtime.tree.AbstractParseTreeVisitor.visitChildren(AbstractParseTreeVisitor.java:46)
	at liquid.parser.v4.LiquidParserBaseVisitor.visitTag(LiquidParserBaseVisitor.java:62)
	at liquid.parser.v4.LiquidParser$TagContext.accept(LiquidParser.java:453)
	at org.antlr.v4.runtime.tree.AbstractParseTreeVisitor.visitChildren(AbstractParseTreeVisitor.java:46)
	at liquid.parser.v4.LiquidParserBaseVisitor.visitAtom_tag(LiquidParserBaseVisitor.java:34)

Which is very hard to figure out what is not implemented.

@msangel
Copy link
Collaborator

msangel commented Aug 20, 2021

code to reproduce?

@jvanzyl
Copy link
Collaborator Author

jvanzyl commented Aug 20, 2021

I'll make a test that has a template with a tag that has not been implemented and it should yield the error above. In my case it was happening as the template I was using made use of a post_url tag. Then that worked and it failed again on another tag.

Actually it tells you when a filter is missing, but I don't think the same happens with tags.

@jvanzyl
Copy link
Collaborator Author

jvanzyl commented Aug 20, 2021

So at this location:

https://github.com/bkiers/Liqp/blob/master/src/main/java/liqp/parser/v4/NodeVisitor.java#L103

Placing something like this:

   String tagName = ctx.Id().getText();
    if (tags.containsKey(tagName)) {
      throw new RuntimeException("No tag exists: " + tagName);
    }

    return new TagNode(tags.get(tagName), expressions.toArray(new LNode[expressions.size()]));

Helped me report and find the tags that are missing. Maybe this isn't the ideal way to do this but something like this to help users determine if there are tags missing. I'm testing various Jekyll sites and there are a bunch of tags I'll have to implement so some better reporting would be good.

@jvanzyl
Copy link
Collaborator Author

jvanzyl commented Aug 20, 2021

@msangel What's the recommend way to create templates with custom filters and tags?

@msangel
Copy link
Collaborator

msangel commented Aug 20, 2021 via email

@jvanzyl
Copy link
Collaborator Author

jvanzyl commented Aug 20, 2021

I'll try and see if there is a test for registering a new tag and using it as this seems not to be working for me. I'll make a test quickly.

@msangel
Copy link
Collaborator

msangel commented May 11, 2022

Thanks for the commit!

@msangel msangel closed this as completed May 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants