If the setting $CFG->navshowmycoursecategories is turned on in Site Administration->Appearance->Navigation, and at least one of the course categories on the top level ($category->parent = 0), is set as hidden, attempting to load any page on the Moodle application will result in the following error message:
Upon further investigation, I found that this error was being triggered on line 1134 of file navigationlib.php, in function initialise(). Since this library file is loaded on every request, this error gets triggered every time. Below is the segment of code where the error occurs:
The exact problem is that the following function call returns bool(false) if $category->parent is set as 0:
This triggers an exception in function has_capability because it expects its 2nd parameter to be of type "context"