Coding error detected: Invalid availability structure

Coding error detected: Invalid availability structure

by CBRC Innovations Department -
Number of replies: 6

Hello. My students seem to be getting this error upon accessing their course. Is there a workaround for this?

The error is: Coding error detected, it must be fixed by a programmer: Invalid availability structure (missing ->op)

Is there a way to fix this? I've double-checked my cron jobs and they are running fine.

I, unfortunately, have no idea what this error means, but I hope you people could help me out, tell me what the problem is and how to resolve this.

If you require more information, I'm free to reply when needed.

Average of ratings: -
In reply to CBRC Innovations Department

Re: Coding error detected: Invalid availability structure

by Howard Miller -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
Switch on Debugging all the way to Developer and tick the display errors box. When it happens again, give us the full trace that should now appear.

It might also help to tell us which version of Moodle this is and some details of your server.
In reply to Howard Miller

Re: Coding error detected: Invalid availability structure

by CBRC Innovations Department -
Thanks for your reply! Here are the details of the debugging error I've found:

Stack trace:
  • line 147 of /availability/classes/tree.php: coding_exception thrown
  • line 237 of /availability/classes/tree.php: call to core_availability\tree->__construct()
  • line 144 of /availability/classes/info.php: call to core_availability\tree->__construct()
  • line 114 of /availability/classes/info.php: call to core_availability\info->decode_availability()
  • line 248 of /availability/condition/completion/classes/condition.php: call to core_availability\info->get_availability_tree()
  • line 772 of /availability/classes/info.php: call to availability_completion\condition::completion_value_used()
  • line 493 of /course/renderer.php: call to core_availability\info::completion_value_used()
  • line 899 of /course/renderer.php: call to core_course_renderer->course_section_cm_completion()
  • line 801 of /course/renderer.php: call to core_course_renderer->course_section_cm()
  • line 993 of /course/renderer.php: call to core_course_renderer->course_section_cm_list_item()
  • line 220 of /theme/moove/classes/format_topics_renderer.php: call to core_course_renderer->course_section_cm_list()
  • line 57 of /course/format/topics/format.php: call to theme_moove_format_topics_renderer->print_multiple_section_page()
  • line 290 of /course/view.php: call to require()


I believe we're using the 3.8 or later build, and our server is a Dedicated Hosting server from Bluehost.

In reply to CBRC Innovations Department

Re: Coding error detected: Invalid availability structure

by Leon Stringer -
Picture of Core developers Picture of Particularly helpful Moodlers

The error suggests there's a course activity with access restrictions set but these are stored incorrectly.

Could you run database query (assuming the table prefix is mdl_ and the database is MySQL or MariaDB):

SELECT * FROM mdl_course_modules WHERE availability IS NOT NULL AND availability NOT LIKE '{"op":%';

and see if anything is returned? It looks like the start of the availability column should be operator op (e.g. '{"op":"&",…'), if that's not present then "Invalid availability structure (missing ->op)" appears.

If there are rows returned then the question is how did this happen? Is this a new Moodle site or one that's been upgraded?

In reply to Leon Stringer

Re: Coding error detected: Invalid availability structure

by Brandon Jimenez -
i could recommend starting here
https://github.com/moodle/moodle/blob/6153be6850869cdc3a6ae925dcf6e688ac481333/availability/classes/tree.php

from there on, you could backtrace what's broken (although @Leon is absolutely right). I had the coding error but with a different exception_thrown, and that helps me greatly in finally identifying it. Hope that helps.
In reply to Leon Stringer

Re: Coding error detected: Invalid availability structure

by Jonathan Lopez -
Es correcto, es un problema con las restricciones de acceso, muy seguramente alguna actividad tiene alguna definición de acceso por grupos, y no hay grupos definidos en el curso u otra regla con una definición errada.

Lo mejor es limpiar todas restricciones, probar el ingreso y definir nuevas reglas.