{"record":{"id":"d656b58319a3f7ee","repo":"moodle/moodle","slug":"preprocesserror-d656b5","errorCode":"preprocesserror","errorMessage":"preprocesserror","messagePattern":"preprocesserror","errorType":"error_code","errorClass":"moodle_exception","httpStatus":null,"severity":"error","filePath":"public/mod/quiz/classes/external/get_users_in_report.php","lineNumber":103,"sourceCode":"            ]\n        );\n\n        $quizobj = quiz_settings::create_for_cmid($cmid);\n        $context = $quizobj->get_context();\n        external_api::validate_context($context);\n\n        $quiz = $quizobj->get_quiz();\n        $cm = $quizobj->get_cm();\n        $course = $quizobj->get_course();\n\n        // Load the report class definition.\n        $file = $CFG->dirroot . '/mod/quiz/report/' . $mode . '/report.php';\n        if (is_readable($file)) {\n            include_once($file);\n        }\n        $reportclassname = 'quiz_' . $mode . '_report';\n        if (!class_exists($reportclassname)) {\n            throw new \\moodle_exception('preprocesserror', 'quiz');\n        }\n        $report = new $reportclassname();\n        // Check access permission.\n        $report->has_permission($context);\n        $data = $report->setup_report_data($quiz, $cm, $course, $context);\n        if (empty($data)) {\n            return [\n                'users' => $users,\n                'warnings' => $warnings,\n            ];\n        }\n        // Retrieve necessary data for report.\n        [$options, $table, $allowedjoins] = $data;\n        static::$context = $context;\n\n        // Get parameter for report.\n        $params = json_decode($params);\n        $options->setup_from_params_array($params);","sourceCodeStart":85,"sourceCodeEnd":121,"githubUrl":"https://github.com/moodle/moodle/blob/48ea8c33227277e916cdd4079dbecef448b37f2c/public/mod/quiz/classes/external/get_users_in_report.php#L85-L121","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","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."],"exampleFix":"// before (web service call)\nmode = \"statisticspro\"   // plugin not installed\n// after\nmode = \"overview\"        // core report that is installed","handlingStrategy":"validation","validationCode":"$mode = 'statistics'; // value destined for get_users_in_report\n$file = $CFG->dirroot . '/mod/quiz/report/' . $mode . '/report.php';\nif (!is_readable($file) || !class_exists('quiz_' . $mode . '_report')) {\n    // fall back to a core report before calling the WS\n    $mode = 'overview';\n}","typeGuard":"function quiz_report_mode_is_available(string $mode): bool {\n    global $CFG;\n    $file = $CFG->dirroot . '/mod/quiz/report/' . $mode . '/report.php';\n    return is_readable($file) && class_exists('quiz_' . $mode . '_report');\n}","tryCatchPattern":"try {\n    $result = mod_quiz_external::get_users_in_report($quizid, $groupid, $mode);\n} catch (moodle_exception $e) {\n    if ($e->errorcode === 'preprocesserror') {\n        debugging('Report mode not available: ' . $mode);\n        $result = mod_quiz_external::get_users_in_report($quizid, $groupid, 'overview');\n    } else {\n        throw $e;\n    }\n}","preventionTips":["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."],"tags":["moodle","quiz","web-service","plugin","class-not-found"],"backgroundTag":"class-not-found","analyzedSha":"48ea8c33227277e916cdd4079dbecef448b37f2c","analyzedAt":"2026-09-14T20:34:48.527Z","contentChangedAt":"2026-09-14T20:34:48.527Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}