ctreffe / alfred

Alfred - A library for rapid experiment development
MIT License
10 stars 1 forks source link

Improve error message for wrong input to Text element #199

Closed jobrachem closed 2 years ago

jobrachem commented 2 years ago

Quoting #153:

For instance, if I give the wrong data type to a Text element for some reason:

import alfred3 as al

exp = al.Experiment()

@exp.member
class TestPage(al.Page):
    def on_each_show(self):
        self += al.Text(13)

I get the following error that does not include my script.py in the stacktrace:

 Exception during experiment execution.
Traceback (most recent call last):
  File "d:\python\expra\venv\lib\site-packages\alfred3\localserver.py", line 144, in experiment
    html = script.exp_session.user_interface_controller.render_html(page_token)
  File "d:\python\expra\venv\lib\site-packages\alfred3\ui_controller.py", line 711, in render_html
    return self.render(page_token=page_token)
  File "d:\python\expra\venv\lib\site-packages\alfred3\ui_controller.py", line 707, in render
    return self.template.render(d)
  File "d:\python\expra\venv\lib\site-packages\jinja2\environment.py", line 1304, in render
    self.environment.handle_exception()
  File "d:\python\expra\venv\lib\site-packages\jinja2\environment.py", line 925, in handle_exception
    raise rewrite_traceback_stack(source=source)
  File "d:\python\expra\venv\lib\site-packages\alfred3\templates\page.html.j2", line 1, in <module>
    {% extends "layout.html.j2" %}
  File "d:\python\expra\venv\lib\site-packages\alfred3\templates\layout.html.j2", line 52, in <module>
    {% block page %}
  File "d:\python\expra\venv\lib\site-packages\alfred3\templates\page.html.j2", line 58, in <module>
    {{ element.web_widget | safe }}
  File "d:\python\expra\venv\lib\site-packages\jinja2\environment.py", line 474, in getattr
    return getattr(obj, attribute)
  File "d:\python\expra\venv\lib\site-packages\alfred3\element\core.py", line 708, in web_widget
    d = self.template_data
  File "d:\python\expra\venv\lib\site-packages\alfred3\element\display.py", line 243, in template_data
    d["text"] = self.render_text()
  File "d:\python\expra\venv\lib\site-packages\alfred3\element\display.py", line 228, in render_text
    text = emojize(text, use_aliases=True)
  File "d:\python\expra\venv\lib\site-packages\emoji\core.py", line 114, in emojize
    return pattern.sub(replace, string)
TypeError: expected string or bytes-like object
2021-11-19 16:20:33,103 - exp.default_id - INFO - experiment id=default_id - session id=sid-349bddcf35de4e87a101c713b081ecdc -
ExperimentSession.abort() called. Aborting session. Reason: error