Shopify / liquid

Liquid markup language. Safe, customer facing template language for flexible web apps.
https://shopify.github.io/liquid/
MIT License
11.11k stars 1.39k forks source link

Is it possible to show error line when there are parsing errors? #1413

Open linuxd3v opened 3 years ago

linuxd3v commented 3 years ago

Hi. im trying to test liquid template that errors out with this error:

Traceback (most recent call last):
        9: from run.rb:11:in `<main>'
        8: from /usr/share/gems/gems/liquid-5.0.0/lib/liquid/template.rb:97:in `parse'
        7: from /usr/share/gems/gems/liquid-5.0.0/lib/liquid/template.rb:110:in `parse'
        6: from /usr/share/gems/gems/liquid-5.0.0/lib/liquid/document.rb:7:in `parse'
        5: from /usr/share/gems/gems/liquid-5.0.0/lib/liquid/document.rb:23:in `parse'
        4: from /usr/share/gems/gems/liquid-5.0.0/lib/liquid/document.rb:55:in `parse_body'
        3: from /usr/share/gems/gems/liquid-5.0.0/lib/liquid/block_body.rb:29:in `parse'
        2: from /usr/share/gems/gems/liquid-5.0.0/lib/liquid/block_body.rb:136:in `parse_for_document'
        1: from /usr/share/gems/gems/liquid-5.0.0/lib/liquid/document.rb:57:in `block in parse_body'
/usr/share/gems/gems/liquid-5.0.0/lib/liquid/document.rb:36:in `unknown_tag': Liquid syntax error: Unknown tag 'json' (Liquid::SyntaxError)

Im new to liquid and my code seems fine.

I cannot understand which line this code refers to as I have multiple variables outputted that begin with "json".

Is there a way to enable line numbers in errors?

ADTC commented 3 years ago

Yes, line numbers would have been helpful. I agree! Shopify does this, so it should be possible in other platforms.

For your case though: It says Unknown tag 'json' so you should look for a tag named json (not a variable). A tag looks like this: {% json ... %}.

A common mistake I sometimes find myself doing is to assign a variable without using the assign tag. So instead of {% assign json = my_json %} I might do {% json = my_json %}. Liquid would misunderstand json to be a tag and give an error.