moodle/moodle · error · moodle_exception
preprocesserror
preprocesserror
Error message
preprocesserror
What it means
moodle_exception('preprocesserror','quiz') is thrown in mod_quiz\external\get_users_in_report when, after including /mod/quiz/report/<mode>/report.php, the expected report class 'quiz_<mode>_report' does not exist. The external web service dynamically loads a quiz report plugin by the 'mode' parameter and instantiates it; an unknown, misspelled, missing, or non-loadable report plugin produces this error. It is a plugin-loading/preprocessing failure before any report data is gathered.
Solutions
- Check the mode value against installed reports (ls mod/quiz/report/) and use a valid one such as 'overview' or 'grades'.
- Confirm mod/quiz/report/<mode>/report.php exists and is readable on the server; redeploy or reinstall the plugin if missing.
- Verify the plugin's report.php declares class quiz_<mode>_report exactly; fix the class name or upgrade the plugin.
- If the plugin was intentionally removed, update the caller/web-service client to stop requesting that mode.
- Clear caches (purge all) so the class_exists check is not operating on stale autoload state.
Example fix
// before (web service call) mode = "statisticspro" // plugin not installed // after mode = "overview" // core report that is installed
Defensive patterns
Strategy: validation
Validate before calling
$mode = 'statistics'; // value destined for get_users_in_report
$file = $CFG->dirroot . '/mod/quiz/report/' . $mode . '/report.php';
if (!is_readable($file) || !class_exists('quiz_' . $mode . '_report')) {
// fall back to a core report before calling the WS
$mode = 'overview';
} Type guard
function quiz_report_mode_is_available(string $mode): bool {
global $CFG;
$file = $CFG->dirroot . '/mod/quiz/report/' . $mode . '/report.php';
return is_readable($file) && class_exists('quiz_' . $mode . '_report');
} Try / catch
try {
$result = mod_quiz_external::get_users_in_report($quizid, $groupid, $mode);
} catch (moodle_exception $e) {
if ($e->errorcode === 'preprocesserror') {
debugging('Report mode not available: ' . $mode);
$result = mod_quiz_external::get_users_in_report($quizid, $groupid, 'overview');
} else {
throw $e;
}
} Prevention
- Enumerate available modes from mod/quiz/report/ directory or plugin list instead of hardcoding mode strings.
- Pin report plugin versions in deployment so all web nodes have the same plugins installed.
- After upgrades, smoke-test each report mode your integrations use.
- Keep custom report class names following the quiz_<mode>_report convention when renaming.
When it happens
Trigger: Calling the get_users_in_report external function with mode set to a report plugin that is not installed, was uninstalled, has a class name that no longer matches quiz_<mode>_report, or whose report.php is not readable (file missing or unreadable include path).
Common situations: Third-party quiz report plugin removed after an upgrade while clients still request its mode; typo in the mode string (e.g. 'attempts' vs 'overview'); custom report plugin never deployed to the web node serving web-service requests; class renamed in a plugin update breaking the naming convention.
Related errors
- invalidfieldtype
- noformdesc
- preprocesserror
- The specified " " contenttype does not exist
- Unknown condition type:
AI-assisted analysis of moodle/moodle@48ea8c3322 (2026-09-14).
Data as JSON: /api/errors/d656b58319a3f7ee.
Report an issue: GitHub.
Appendix: source
Thrown at public/mod/quiz/classes/external/get_users_in_report.php:103
]
);
$quizobj = quiz_settings::create_for_cmid($cmid);
$context = $quizobj->get_context();
external_api::validate_context($context);
$quiz = $quizobj->get_quiz();
$cm = $quizobj->get_cm();
$course = $quizobj->get_course();
// Load the report class definition.
$file = $CFG->dirroot . '/mod/quiz/report/' . $mode . '/report.php';
if (is_readable($file)) {
include_once($file);
}
$reportclassname = 'quiz_' . $mode . '_report';
if (!class_exists($reportclassname)) {
throw new \moodle_exception('preprocesserror', 'quiz');
}
$report = new $reportclassname();
// Check access permission.
$report->has_permission($context);
$data = $report->setup_report_data($quiz, $cm, $course, $context);
if (empty($data)) {
return [
'users' => $users,
'warnings' => $warnings,
];
}
// Retrieve necessary data for report.
[$options, $table, $allowedjoins] = $data;
static::$context = $context;
// Get parameter for report.
$params = json_decode($params);
$options->setup_from_params_array($params);View on GitHub (pinned to 48ea8c3322)