moodle/moodle · error

Invalid values received for series.

Error message

Invalid values received for series.

What it means

After confirming values is an object/array, the Series constructor also requires it to contain at least one element. An empty array is rejected because a chart series with no values is meaningless to render.

Solutions

  1. Ensure the values array has at least one element before constructing the series.
  2. Guard the chart-build code: skip or defer rendering when the dataset is empty.
  3. Fix upstream data fetching/filtering so the array is populated.

Example fix

// before
const series = new Series('Sales', records.filter(r => r.valid)); // may be []
// after
const valid = records.filter(r => r.valid);
if (valid.length === 0) return;
const series = new Series('Sales', valid);
Defensive patterns

Strategy: validation

Validate before calling

if (!Array.isArray(values) || values.length < 1) {
    throw new TypeError('Series values must be a non-empty array');
}
const series = new Series(label, values);

Type guard

function isNonEmptyArray(v) { return Array.isArray(v) && v.length > 0; }

Try / catch

try {
    const series = new Series(label, values);
} catch (e) {
    if (e.message === 'Invalid values received for series.') {
        return null; // skip chart with no data
    }
    throw e;
}

Prevention

When it happens

Trigger: new Series('label', []) — an array with length 0.

Common situations: Filtering a dataset that matched nothing before charting; data still loading asynchronously so the array is empty at chart-build time; an API response returning an empty list.

Understand the failure class

Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.

Related errors


AI-assisted analysis of moodle/moodle@48ea8c3322 (2026-09-14). Data as JSON: /api/errors/94174211c488f59e. Report an issue: GitHub.

Appendix: source

Thrown at public/lib/amd/src/chart_series.js:40

 */
define([], function() {

    /**
     * Chart data series.
     *
     * @class
     * @param {String} label The series label.
     * @param {Number[]} values The values.
     */
    function Series(label, values) {
        if (typeof label !== 'string') {
            throw new Error('Invalid label for series.');

        } else if (typeof values !== 'object') {
            throw new Error('Values for a series must be an array.');

        } else if (values.length < 1) {
            throw new Error('Invalid values received for series.');
        }

        this._colors = [];
        this._label = label;
        this._values = values;
    }

    /**
     * The default type of series.
     *
     * @type {Null}
     * @const
     */
    Series.prototype.TYPE_DEFAULT = null;

    /**
     * Type of series 'line'.
     *

View on GitHub (pinned to 48ea8c3322)