Undefined index error when displaying H5P content

Our Moodle content creators (not me) are reporting an issue with displaying content generated by the H5P plugin. When they try to create new content the system shows an error message with no error text. I changed logging in our system to developer mode and found the following error:

One further error appears at the top of the page as follows:

Notice: Undefined index: Cannot read file. Either the file does not exist or there is a permission problem. in /home/www/html/learning/mod/hvp/classes/framework.php on line 371.

I have checked file permissions of this referenced file on the system. They look correct relative to the rest of our Moodle system. The php file exists on the server. Any thoughts on why this may be happening? Our Moodle course folks tell me that this worked properly about six months ago. They are now trying to stand up the system for a new class and are running into this issue. I appreciate any help anyone may offer!

thomasmars's picture

Hi,
It seems like a php error is thrown when attempting to export a library, then is caught at line 1577 in h5p.classes.php, which tries to translate the error message into a readable string, but this does not have a valid translation.

The underlying problem is that the php error is thrown in the first place when exporting a library. This could be for several reasons and is not clear from the given description of the errors. It is however likely that it happens when trying to copy files during the export, because of permissions. You should investigate the error message caught at line 1578 in h5p.classes.php, where the error $e is caught. For instance by putting " var_dump($e);exit; " at the line then reproducing the error.

Thank you for your response! I apologize for the delay. It has been an aggressive few weeks here in the IT Office. I ran the var_dump() function as you described and found the following error:

object(file_exception)#392 (12) { ["errorcode"]=> string(20) "storedfilecannotread" ["module"]=> string(5) "error" ["a"]=> string(0) "" ["link"]=> string(0) "" ["debuginfo"]=> string(71) "/path/to/moodledata/filedir/97/f4/97f4811be36725ab8df9d793be66fa2abf57d057" ["message":protected]=> string(82) "Cannot read file. Either the file does not exist or there is a permission problem."

 

I verified that the file does not exist. Any thoughts on where to get this file? Our Moodle installation has an f5 directory in the path but no f4. Directory f5 is empty. Creating directory f4 manually (and checking permissions) does not resolve this issue. What generates this file?

thomasmars's picture

Hi, would be nice to see the stack trace as well. The file is most likely a dependency of the content type from what I can deduce. If this is the case then the files are generated when you first download the content type, or upload content that includes the content type.

If the file does not exist there, then the library may be missing a dependency or something is likely wrong with where your libraries are saved. Please make sure that the server has proper read write permissions for where temporary files are stored, where your H5P libraries are stored and where the exported H5Ps are stored. This should normally be in the moodleData folder.

How would one produce this requested stack trace? Apologies for my lack of knowledge. Thanks for your help!

thomasmars's picture

You can for instance follow the instructions that Moodle gives for debugging errors, or you can look in your php error log. You might have to remove the try/catch wrappers in h5p.classes.php L#1554-1579, since they swallow the error without reporting it back to the php runtime.