Cannot read property 'getFiles' of undefined

Cannot read property 'getFiles' of undefined

by Howard Miller -
Number of replies: 2
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

We had a student reporting this problem. They described it thus...

"I have downloaded a course.  Then when I go to the desktop app and attempt “offload all course data” it is coming up with this error message.  I have also attempted to go into manage storage to remove the course and the same error appears.  Unfortunately I then cannot download another course as I have already filled my two course quota."

This is a screenshot of the error...


Any ideas?

Average of ratings: -
In reply to Howard Miller

Re: Cannot read property 'getFiles' of undefined

by hlipper john -

In JavaScript almost everything is an object, null and undefined are exceptions. This error  occurs when a property is read or a function is called on an undefined variable. Undefined means that a variable has been declared but has not been assigned a value. In JavaScript, properties and functions can only belong to objects. Since undefined is not an object type, calling a function or a property on such a variable causes the TypeError: Cannot read property of undefined.  

If you are not sure a variable that will always have some value, the best practice is to check the value of variables for null or undefined before using them. To avoid getting these types of errors, you need to make sure that the variables you are trying to read do have the correct value. This can be done in various ways. You can do if checks before dealing with objects whose values are bound to change:

if (myVar !== undefined) {

    ...

}

Or

if (typeof(myVar) !== 'undefined') {

    ...

}