Hello dear halftrainedharry,
this error started appearing after updating to the latest version of MODX.
it appears when i surf in any of contexts as well as the main one. I have over 10 context / subdomains contexts settings is like:
It’s unclear, when exactly this error message is created.
It’s thrown here in the code in the function _initContext().
The function _initContext() is called on every request to initialize the context and after a context switch.
The line $modx->switchContext($cKey); will call the _initContext() function again. But as the context “mgr” is explicitely excluded in the code ($query->where(array('modContext.key:NOT IN' => array('web', 'mgr')));), it’s unlikely that this plugin is the source of the error.
The best way is to use a debugger like Xdebug.
But this requires some experience with reading and debugging code.
Alternatively you could try logging additional information to the MODX error log. This may help finding the cause of the issue.
For example you could (temporarily) add the line $this->log(modX::LOG_LEVEL_ERROR, 'Stack trace: ' . (new \Error)->getTraceAsString());
right after the line that logs the 'Could not prepare context...' error message.
This logs the stack trace and tells you more about the series of function calls that leads to the error.