UCL-INGI / INGInious

INGInious is a secure and automated exercises assessment platform using your own tests, also providing a pluggable interface with your existing LMS.
http://www.inginious.org
Other
202 stars 139 forks source link

[Frontend] Feedback Symbol Parsing Issue #952

Closed javawolfpack closed 1 year ago

javawolfpack commented 1 year ago

Describe the bug It appears that the way feedback is rendered from a template or generally, there are a few issues I've noticed. Firstly newline symbols are ignored. To fix this, I made a template, and have gone so far as to have the template iterate over output from say make split by new lines in my run script.

Have now discovered that there are parsing exceptions in the syslogs from uwsgi:

<string>:5: (ERROR/3) Unexpected indentation.
<string>:7: (SEVERE/4) Unexpected section title.
^
;

Interestingly I get the result I want outside of a Parsing Error message, which might be confusing for my students.

INGInious installation details

To Reproduce Steps to reproduce the behavior:

  1. Have a run script run make
  2. Set the compile message error as feedback
  3. For the specific error, split error on newline, have template loop over lines and render them to provide multi-line formatted feedback.

Expected behavior Basically the screenshot without the "Parsing failed" message

Screenshots

Screenshot 2023-05-29 at 11 13 40 AM

Desktop (please complete the following information):

Additional context None

javawolfpack commented 1 year ago

For reference in both cases, err is the stderr from subprocess for make decoded as utf-8:

Templates and run code 1:

Compiler Error:
{{ err }}

Run Code:

feedback_msg = {}
feedback_msg["err"] = err
feedback.set_feedback_from_tpl("compiler", feedback_msg, append = True)

Templates and run code 2:

Compiler Error:
{% for line in err %}
{{ line }}
{% endfor %}

Run Code:

feedback.set_feedback_from_tpl("compiler",
        {"err":err.split("\n")}
)

Both generate the same parsing error message and logs.

javawolfpack commented 1 year ago

Also, I'm pretty sure it's the ^ and ; symbols in the output that is the culprit.

anthonygego commented 1 year ago

Feedback is parsed as reStructuredText using the docutils library (https://docutils.sourceforge.io/docs/user/rst/quickstart.html) and indents have syntaxic meaning. For code-blocks, you need to use the .. code :: directive or simply :: and indent each line in order for docutils to detect the end of the code block. For new paragraphs you need a double \n

The template should therefore more or less look like (first case):

Compiler error:

::

{{ err | indent(first=True,blank=True) }}

using the indent jinja filter : https://jinja.palletsprojects.com/en/3.0.x/templates/#jinja-filters.indent

or (second case)

Compiler error:

::

    {% for line in err %}
    {{ line }}
    {% endfor %}
javawolfpack commented 1 year ago

Ok, that :: directive was what I was missing. Thanks.