Format check initialization fail

Format check initialization fail

by Bernat Martinez -
Number of replies: 26

Moodle 3.1.1, PHP7 and clean theme

When open a formulas question it appears an image  in the lower right part of the page when the mouse is over it shows the tooltip : Format check initialization fail (1/190)

It seems to be that the png  image which is in the folder of  question/type/formulas/pix  cannot be initialized

I have purged all caches but don't know what to do more. Any ideas?

It is PHP7 to blame?

Average of ratings: Useful (1)
In reply to Bernat Martinez

Re: Format check initialization fail

by Mary Evans -
Picture of Core developers Picture of Documentation writers Picture of Peer reviewers Picture of Plugin developers Picture of Testers

Hi,

Since this is not a theme related issue entirely, I am moving it over to Tim Hunt in the QUIZ Forum as he is the Questions Guru and certainly more knowledgeable about this, PHP7 and Moodle.

Thanks

Mary

In reply to Bernat Martinez

Re: Format check initialization fail

by Bernat Martinez -

I answer myself, it was a browser issue, it happens in Chrome only.

For the moment formulas question type works fine in Moodle3.1.1 & PHP7

Sorry for the inconvenience

Average of ratings: Useful (1)
In reply to Bernat Martinez

Re: Format check initialization fail

by Mary Evans -
Picture of Core developers Picture of Documentation writers Picture of Peer reviewers Picture of Plugin developers Picture of Testers

In that case it is missing webkit- prefix in the CSS I guess?

Cheers

Mary

In reply to Bernat Martinez

Re: Format check initialization fail

by Mary Evans -
Picture of Core developers Picture of Documentation writers Picture of Peer reviewers Picture of Plugin developers Picture of Testers

I was thinking of fixing this if it is a bug, be it browser related, but could not find "formula" in the moodle/question/type/ directory.

See here: https://github.com/lazydaisy/moodle/tree/MOODLE_31_STABLE/question/type

Can you tell me which type you used exactly, please?

Thanks

Mary

In reply to Mary Evans

Re: Format check initialization fail

by Bernat Martinez -

Thanks for your effort. 

This is the link to the plugin 

https://moodle.org/plugins/qtype_formulas

It seems only happens with CHROME using  a MAC. It happens I have recently upgraded to El Capitan, in older versions  I didn't noticed it

See the red triangle in the right lower part of the image.

This icon is used  for warning you are writing forbidden characters in an answer field, it appears beside the answer field. Obviously this feature doesn't work now

In reply to Bernat Martinez

Re: Format check initialization fail

by Matthias Giger -
Picture of Particularly helpful Moodlers

I have exactly the same problem.

It occurs in PHP 5.6 and in PHP 7.0 (I just did a short test).

The triangle is shown in Chrome, Opera and Vivaldi, but not in Firefox or Edge.


In reply to Matthias Giger

Re: Format check initialization fail

by Bernat Martinez -

Thanks for reporting this. 

It is strange thing, first only happened using Chrome with Mac (not in Safari and Firefox), later it appeared in Chrome with Windows. It seems that some browser actualization has created a CSS problem. 

Any idea how to solve it would be appreciated

In reply to Bernat Martinez

Re: Format check initialization fail

by Renaat Debleu -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers

The error happens in line 756 of the file formatcheck.js

['algebraic_formula', false, 'a**b'],

If you remove this line, the error is gone. But also the extra formula check.

Does anyone has a clue why some browsers return true and other browsers false on evaluating a**b?

Average of ratings: Useful (2)
In reply to Renaat Debleu

Re: Format check initialization fail

by Bernat Martinez -

It works, thanks.

May I ask you what type of procedure do you use to detect where the error happens.


In reply to Bernat Martinez

Re: Format check initialization fail

by Renaat Debleu -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers

  1. On a Moodle test server: disable javascript caching and enable debugging mode
  2. Read the code: you quickly detect that the error is thrown in line 897 (f (!common.pass && unittest_fail_show_icon)  signal_fail(common) so knowing the contents of common would be great
  3. In your browser : open the page that produces the error and press F12 to see the debugging panel
  4. navigate to sources panel to find and open formatcheck.js folder
  5. click on the number 897 to pause script pause
  6. Press CTRL R to do a page refresh
  7. The pages reloads but stops execution on line 897
  8. In de local variables, you can see the contents of common and see the failcase :error
  9. Press F8 to resume script execution
  10. Report your findings to the Moodle community...
Average of ratings: Useful (4)
In reply to Renaat Debleu

Re: Format check initialization fail

by Bernat Martinez -

Thanks a lot for your clear explanation,  I'm not a programmer but I can understand the procedure

In reply to Bernat Martinez

Re: Format check initialization fail

by Dominique Bauer -
Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Plugin developers

On another note, I also have this error in Chrome but I can not complain too much because, for me, it's almost better if this routine is not working, although the red error triangle at the bottom right of the screen is a bit distracting.

In my use of the Formulas question, all the answers are either a number or a number and a unit. If {_0} and {_0}{_u} are used, the width of the input box indicates whether students must enter a number or a number and a unit. If {_0} and {_0} {_u} (separated by a space) are used, the fact that there are either one or two input boxes indicates even more clearly what students should enter. Hence the routine's recall of what should be entered is somewhat superfluous.

The syntax checking, for example for an input of 10e3 mm^2, also seems a bit superfluous, since in any case students have to be reminded of the syntax rules. Also since the verification is done as the answer is input, it may indicate an error while the input is not complete, for example when it is at 10e3 mm^. See the first screenshot below.

So assuming that the routine is not absolutely necessary, another advantage is to gain some space. Since my sub-questions are generally arranged one above the other in a table, I have to provide space between each sub-question when the routine is active, so that the message of a sub-question does not cover the input box of the next sub-question. The Enter key does not release from an input box and it is only natural to click the next box below to enter the next response, which is impossible if this box is hidden. With the routine inactive, the sub-questions can be moved closer together and the answer pages becomes shorter, reducing scrolling. The screenshots below illustrate the above points.

Thanks to Bernat Martinez for bringing this point up and to Renaat Debleu for showing how to disable the routine if wanted.

In reply to Dominique Bauer

Re: Format check initialization fail

by Jean-Michel Védrine -

Dominique,

You can customize the display of the error checking to suit your needs by editing some lines at the beginning of the formatcheck.js file

And fortunately these lines are well commented so it's easy to see what they do:

    var use_format_check = true;    // If it is set to false, no format check will be used and initialized.
    var show_hinting_type = null;   // Show the type hinting under the input box, such as 'Number', 'Unit'. null means use the individual setting in variable types below.
    var show_interpretation = null;   // Show the interpretation of the formula under the input box. null means use the individual setting in variable types below.
    var show_warning = null;   // Show the warning sign if the input is wrong/not interpretable. null means use the individual setting in variable types below.
    var unittest_fail_show_icon = true; // Show an icon at the low right corner if the format check testing fails
    var unittest_fail_show_details = false;  // Show the detail test case that it fails.

In your case you can set both  show_hinting_type and show_interpretation to false.

Hon Wai Lau's code even permit to set some of these flags to true or false only for numbers or for algebraic formulas for instance, see the lines 

var types = [
        ['unit', true, true, true],                 // For the unit input box.
        ['number', true, true, true],               // For the number input box.
        ['number_unit', true, true, true],          // Input box with number and unit together.
        ['numeric', true, true, true],              // Allow the combination of numbers and operators + - * / ^ ( ).
        ['numeric_unit', true, true, true],         // Input box with numeric and unit together.
        ['numerical_formula', true, true, true],    // Allow the combination of numbers, operators and functions.
        ['numerical_formula_unit', true, true, true],   // Input box with numerical formula and unit together.
        ['algebraic_formula', true, true, true],    // Allow the combination of numbers, operators, functions and variables.
        ['editing_unit', false, true, true]         // Used for the unit in editing interface.
    ]; 
In reply to Bernat Martinez

Re: Format check initialization fail

by hon wai lau -
I just see this issues at github.

This is purely javascript related problem (not CSS or PHP). The script is used to provide the real-time checking of student's input. During the initialization, it will perform 190 checks to ensure the javascript works exactly the same as the PHP backend. I never expect the inconsistency really happen! The triangle is just used during my testing and never intend to show in a real situation.

At the moment, it may be fine to just delete the particular test case as mentioned above. If you are not using the algebraic test, the chance is that you are ok. Otherwise, it may provide inconsistency message to students in a rare case (really rare), such that the students will get confused.

As what have been reported above, I suspect that it is a bug in the new javascript engine in Chrome, since it only happens in the new version of Chrome. If it is really the case, it should be reported to Chrome. Alternatively, it is the bugs in my code, but I don't see it now. It should be related to the regex part of the javascript engine. I don't have time to test it now.

Is it still happening? In Chrome only, or in other browsers too?
Average of ratings: Useful (1)
In reply to hon wai lau

Re: Format check initialization fail

by Bernat Martinez -

Yes, it is still happening in Chrome and now in Firefox too. But not in Safari.

Thanks for having a look at this issue, we are extremely happy with formulas question

In reply to hon wai lau

Re: Format check initialization fail

by Jean-Michel Védrine -

Hello,

I just discovered this thread. What would be the best way to solve this issue ? Now in december 2017 with what browsers does it appear ( I tested with chrome latest version and can see the problem)

In reply to Jean-Michel Védrine

Re: Format check initialization fail

by Bernat Martinez -

Hello, 

Now in version 3.4  it happens in Chrome, Firefox and Safari

In reply to Bernat Martinez

Re: Format check initialization fail

by Jean-Michel Védrine -

Well at least this is consistent smile

I wil try to study the problem. Comments welcome.

In reply to Jean-Michel Védrine

Re: Format check initialization fail

by Jean-Michel Védrine -

This is totally unrelated.

As Hon Wai said 

"During the initialization formatcheck.js it will perform 190 checks to ensure the javascript works exactly the same as the PHP backend"

So you may wonder where are the tests for the php backend?

They are in the variables.php file (this file is the workhorse of the formulas question type where all the magic is done smile  and I learned the hard way that you have to be very cautious when you make any change to it)

They are commented and you have to uncomment one line at the end to run the tests.

Since a long time my thinking was that today it would be better to have automated tests.

Now that each time I push a new commit at my github automated tests are run, see https://travis-ci.org/jmvedrine/moodle-qtype_formulas, but don't be frightened by all the orange and red here, most of the "errors" and "violations" are just coding style problems that are unimportant (and very risky) to fix.

So this morning I took the task to transform all Hon Wai Lau tests in variables.php into phpunit tests, the result is here :

https://github.com/jmvedrine/moodle-qtype_formulas/blob/master/tests/variables_test.php

Good news : most of the tests are passing, in fact all of them minus 4 (see Travis job, the phpunit section is all green)

So we know that the formulas engine is working, good for all formulas users smile

But 4 tests are falling (those that are currently commented in my file)

a=3 6; in the variable assignement test produces a parseerror unexpected '$a' (T_VARIABLE) here

https://github.com/jmvedrine/moodle-qtype_formulas/blob/master/variables.php#L946

and 3 tests are failing in the algebraic formula test (a- ,  *a and a**b)

But the good new is that all these tests have a false as their first element so it's the sign that the parser fails on expressions that are incorrect

So most probably correct answers from students are correctly parsed and graded.

But I still need to investigate what is causing these failures.




In reply to Jean-Michel Védrine

Re: Format check initialization fail

by Jean-Michel Védrine -

This rather funny, when I said "This is totally unrelated." I was completely wrong

It seems that in all modern browser's javascript engine that I have tested a**b is equivalent to a^b and this is why the Format check initialization was failing

just changing the line in formatcheck.js to             ['algebraic_formula', true, 'a**b'],

solve the problem reported by the original poster of this thread.

I don't know when this change was decided but the same operator was introduced in php 5.6 (I seems to remember that ** have been used in Python  for ages)

So this also solve one of my 4 problems in the variables tests.

In reply to Jean-Michel Védrine

Re: Format check initialization fail

by Bernat Martinez -

Perfect!!! It works

Thanks a lot, Jean-Michel.

In reply to Bernat Martinez

Re: Format check initialization fail

by Jean-Michel Védrine -

So I think we can consider this problem as solved.

The only problem would be for sites that want to support old browsers. in that case it is better to comment that line in formatcheck.js

In reply to Jean-Michel Védrine

Re: Format check initialization fail

by Jean-Michel Védrine -

Just a note on this thread that the 2 remaining tests that had problems (a- and *a) are now fixed this was caused by a change in PHP 7.x for the eval function : before PHP 7.x  if the expression to evaluate had a syntax error, the eval function just returned false. Now it throws an exception and stops the script.

Including this line in a try {  } catch block resolved the issue.

See https://moodle.org/mod/forum/discuss.php?d=366549 for the details