moodle/moodle · error · moodle_exception
errorinvalidindicator
errorinvalidindicator
Error message
errorinvalidindicator
What it means
moodle_exception('errorinvalidindicator', 'analytics', '', $indicator) is thrown by \core_analytics\model::indicator_classes() — invoked from create() and update() — when an entry in the indicators array fails \core_analytics\manager::is_valid($indicator, '\core_analytics\local\indicator\base'). Each indicator must be a class name (string) or object implementing/extending the indicator base interface. The thrown message embeds a stringified version of the offending value to ease diagnosis.
Solutions
- Ensure every indicators entry is the fully-qualified class name of a class extending \core_analytics\local\indicator\base, e.g. '\core_course\analytics\indicator\activity_completion'
- Validate each entry with \core_analytics\manager::is_valid($indicator, '\core_analytics\local\indicator\base') before calling create/update
- List available indicators via \core_analytics\manager::get_indicator_calculators() (or the target's indicators) instead of hand-writing names
- Re-add indicators from plugins that were removed/renamed after a site upgrade
Example fix
// before $model->update(true, ['activity_completion']); // after $model->update(true, ['\\core_course\\analytics\\indicator\\activity_completion']);
Defensive patterns
Strategy: validation
Validate before calling
foreach ($indicators as $i => $indicator) {
if (!\core_analytics\manager::is_valid($indicator, '\\core_analytics\\local\\indicator\\base')) {
throw new Exception('Invalid indicator at index ' . $i . ': ' . print_r($indicator, true));
}
}
$model->update(true, $indicators); Type guard
function is_indicator($indicator): bool {
return \core_analytics\manager::is_valid($indicator, '\\core_analytics\\local\\indicator\\base');
} Try / catch
try {
$model->update(true, $indicators);
} catch (\moodle_exception $e) {
if ($e->errorcode === 'errorinvalidindicator') {
debugging('Bad indicator supplied: ' . $e->debuginfo, DEBUG_DEVELOPER);
}
} Prevention
- Source indicator names from \core_analytics\manager::get_indicator_calculators() or the target's indicator list, not hand-written strings
- Keep fully-qualified class names with leading backslash in stored config
- Re-validate indicator ids after plugin upgrades/uninstalls
- Log the offending value before update() so the stringified indicator in the exception is actionable
When it happens
Trigger: Calling $model->create() or $model->update() with an indicators array containing: a class name that does not exist; a class not extending \core_analytics\local\indicator\base; a non-scalar non-object value (e.g. null or an array element) that stringifies to garbage; an object of an unrelated class.
Common situations: Copy-pasted indicator class names missing a backslash or namespace; custom indicator plugin uninstalled so stored names no longer resolve; passing indicator IDs instead of class names; typos in \lang strings or form multi-select values mixed into the indicators array.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- errorpredictionformat
- A self conversation can not have more than one user.
- A valid forum ID is required to generate a summary report.
- Activity '' cannot be used as the default idnumber. The…
- An individual conversation can not have more than two users.
AI-assisted analysis of moodle/moodle@48ea8c3322 (2026-09-14).
Data as JSON: /api/errors/4874a7c4acdb6c71.
Report an issue: GitHub.
Appendix: source
Thrown at public/analytics/classes/model.php:1765
/**
* Utility method to return indicator class names from a list of indicator objects
*
* @param \core_analytics\local\indicator\base[] $indicators
* @return string[]
*/
private static function indicator_classes($indicators) {
// What we want to check and store are the indicator classes not the keys.
$indicatorclasses = array();
foreach ($indicators as $indicator) {
if (!\core_analytics\manager::is_valid($indicator, '\core_analytics\local\indicator\base')) {
if (!is_object($indicator) && !is_scalar($indicator)) {
$indicator = strval($indicator);
} else if (is_object($indicator)) {
$indicator = '\\' . get_class($indicator);
}
throw new \moodle_exception('errorinvalidindicator', 'analytics', '', $indicator);
}
$indicatorclasses[] = $indicator->get_id();
}
return $indicatorclasses;
}
/**
* Clears the model training and prediction data.
*
* Executed after updating model critical elements like the time splitting method
* or the indicators.
*
* @return void
*/
public function clear() {
global $DB, $USER;
View on GitHub (pinned to 48ea8c3322)