jcrodriguez-dis / moodle-mod_vpl

Virtual Programming Lab for Moodle (Module)
GNU General Public License v3.0
100 stars 87 forks source link

Error prone parsing of proposed grade #160

Closed jojoob closed 7 months ago

jojoob commented 10 months ago

We had a case were a lecturer customized the automatic program assessment to automate the evaluation and grading. His python script for the evaluation used print('Grade :=>> {}/100'.format(grade_count)) which produces output like Grade :=>> 85/100.

As soon as a submission was evaluated opening the editor led to the following error: Screenshot from 2023-11-09 14-41-07

Default exception handler: Exception - number_format(): Argument #1 ($num) must be of type float, string given Debug:
Error code: generalexceptionmessage
* line 8852 of /lib/moodlelib.php: TypeError thrown
* line 8852 of /lib/moodlelib.php: call to number_format()
* line 682 of /mod/vpl/vpl_submission.class.php: call to format_float()
* line 1308 of /mod/vpl/vpl_submission.class.php: call to mod_vpl_submission->get_grade_core()
* line 229 of /mod/vpl/forms/edit.class.php: call to mod_vpl_submission->get_ce_for_editor()
* line 109 of /mod/vpl/forms/edit.json.php: call to mod_vpl_edit::load()
, referer: https://example.com/mod/vpl/forms/edit.php?id=1234&userid=5678

After investigation it turned out that the /100 part triggered the error.

The analysis of the error showed that mod_vpl_submission->find_proposedgrade() just grabs everything behind Grade :=>> until the end of the line. mod_vpl_submission->get_ce_for_editor() passes that value to mod_vpl_submission->get_grade_core() which in turn calls Moodles format_float() and finally PHPs number_format().

I propose checking the grabbed part to be a number and if it is not showing a descriptive error message to the user. Or at least doing a silent conversation or cast to float to prevent that error message above. In any case the documentation should include the exact format of the grade line with an example.


We are using mod_vpl version 4.2.2 on Moodle 4.1 running with PHP 8.1 and VPL execution server 3.0.1.

jcrodriguez-dis commented 9 months ago

Dear @Jojoob, Thank you for your thorough and insightful bug report regarding the issue encountered with custom automated program assessment in VPL 4.2.2. In response to your findings, we have implemented a solution in the VPL 4.2.3 release. If a non-numeric format is detected, VPL will display an error message to the user, indicating the specific nature of the format issue. This should effectively prevent the type of error you encountered and provide more clarity to users when input format issues arise. Additionally, as per your suggestion, we are updating our documentation to explicitly specify the expected format for grade lines, complete with example formats. This should aid in preventing similar misunderstandings in the future. We value your contribution to improving. Best regards, Juan Carlos

jcrodriguez-dis commented 7 months ago

Resolved in VPL 4.2.3