-
Notifications
You must be signed in to change notification settings - Fork 1
Syntax error prevention and traceback readability #3
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
Syntax error prevention and traceback readability #3
Conversation
8cb5532
to
369d3b1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good to me. Thank you @michalpokusa!
I tested successfully on an ESP32-S3 based device with a modified version of the httpserver_templates.py
from HTTPServer repo examples. Tested with both valid and invalid sytnax for:
- if statement
- for loop
- while loop
Would there be any possibility of being able to show the line number of the offending invalid syntax within the error? something like this:
SyntaxError: Missing {% if ... %} block for {% endif %} at line 43
@FoamyGuy Thanks for review and merging. Regarding the exact line, it is a bit tricky considering all the loops, blocks, includes etc. I do not really have a good idea how this could work in order to be precise about exact place where error occured. I will try to tinker with it this week, maybe I will come up with something. |
Updating https://github.com/adafruit/Adafruit_CircuitPython_TemplateEngine to 1.2.0 from 1.1.0: > Merge pull request adafruit/Adafruit_CircuitPython_TemplateEngine#3 from michalpokusa/syntax-error-prevention-and-traceback-readability Updating https://github.com/adafruit/Adafruit_CircuitPython_Bundle/circuitpython_library_list.md to NA from NA: > Updated download stats for the libraries
Overall this PR makes it easier to not make mistakes when writing templates, as it will raise error in more cases instead of silently allowing bad syntax that will result in unexpected rendered string.
💥 Breaking changes:
Now it will expicitly say what is wrong, e.g.
SyntaxError: Missing {% while ... %} block for {% endwhile %}
🛠️ Updated/Changed:
Template
constructor will raise error if provided template is incorrect e.g. has unclosedif
,for
orwhile
_create_template_rendering_function
automatically addspass
where it might be needed, e.g. when someone puts empty loop where the ending token is right after the starting one🏗️ Refactor:
ValueError
s for bad template syntrax are nowSyntaxError
s