-
Notifications
You must be signed in to change notification settings - Fork 148
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
Apply() can generate a Moodle Error #1279
Comments
Different context, similar problem: |
Sorry about this. To be honest, the error trapping is one of the most difficult parts of the whole project! But, we should probably not throw a Moodle error for sure here, since that leaves a question author at a dead end from which they can't recover. The problem is that the parser ends up getting back the expression "(b+1)-(b+1)(d+1)" from Maxima, and when we try to parse that we get the error (not from what you typed, but from what Maxima creates). Since this is an entirely internal problem, we throw an exception there, rather than an error to the user. This is the line throwing the error One option is to change that exception to throw an error attached the statement. Another option to to allow this kind of expression. Maxima does allow input like "(b+1)(d+1)". @aharjula, do you have a view? |
@sangwinc well we have that runtime check for evil things to call inside Maxima happening just before the call. It could, in theory, check if the thing being called is not an identifier or string and error out there. Note that different types of "apply"-like constructs can generate different checks and different "applys" work with different types of "names" for the function and we do have two different types of tests constructed in 996. That will have a cost, as the check will have to happen for everything. But in this case, we really should error out instead of returning something nonsensical we cannot parse. Basically, to fix this, both |
I think we need to do the check within Maxima itself, after we have evaluated expressions. The problem occurs within Maxima I think, and we need to check at the point we send values back from Maxima to PHP. E.g. in |
Well However, there is a problem because the logic of |
Yes, @aharjula I'm just playing with all that....! |
OK, so it turns out that some questions rely on sophisticated Maxima making use of application of compound functions. I'm sure that restricting something like this (i.e. legal in Maxima, but not in STACK) will break things, and so I'm going to propose an option which throws an error by default (which STACK catches, avoiding a Moodle exception) but which also allows an advanced question author the option to use this facility. I really don't want to needlessly break a whole bunch of advanced stuff! |
@aharjula could you review and approve this proposed fix please? I'd very much value your thoughts on this. Thanks, |
@sangwinc, maybe for the next parser we can allow this without having to do that rewrite to apply for output. It looks funny if outputted through Liking that I can surround just the things I want to have this, with the setting and get warnings for the other bits that I di into intend:
In any case, it did not seem to immediately break anything, but it will probably slow down CAS actions a bit as it is now executed for absolutely every single outputted function call and statement. Some mistargeting of the errors, though. If I place |
Thanks @aharjula. Are you able to help fix the error targeting? I'm not sure I fully understand the order in which things are executed/evaluated. Chris |
Finally, got the time to look at this... A bit too big a change:
As to why exactly we get errors in the first teachers' answers in the inputs, I actually misdiagnosed it. I had |
Thanks @aharjula. I've slept on this and propose we make this the first fix after we release 4.8.0. That gives us the whole development cycle to test and confirm we're happy. My proposed change is major in that it affects every interaction with the CAS. And we have questions which will break, and I'd like time to fix them. The actual problem is confined to a very specific edge case which is not really that common. We'll fix it, but the other risks are quite high.... |
Clumsy use of apply() can generate a Moodle error. The problem only seems to occur in the question variables when the first argument is an array.
For example, write "apply(a[1],[3]);" in the question variables. Of course, such a line without context is nonsense, but it should generate at most a STACK error and certainly not a Moodle error.
I checked it with both of my systems (one with Moodle 4.4.3, the other with 4.3, both with STACK 4.7).
The text was updated successfully, but these errors were encountered: