{"record":{"id":"94174211c488f59e","repo":"moodle/moodle","slug":"invalid-values-received-for-series","errorCode":null,"errorMessage":"Invalid values received for series.","messagePattern":"Invalid values received for series\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"public/lib/amd/src/chart_series.js","lineNumber":40,"sourceCode":" */\ndefine([], function() {\n\n    /**\n     * Chart data series.\n     *\n     * @class\n     * @param {String} label The series label.\n     * @param {Number[]} values The values.\n     */\n    function Series(label, values) {\n        if (typeof label !== 'string') {\n            throw new Error('Invalid label for series.');\n\n        } else if (typeof values !== 'object') {\n            throw new Error('Values for a series must be an array.');\n\n        } else if (values.length < 1) {\n            throw new Error('Invalid values received for series.');\n        }\n\n        this._colors = [];\n        this._label = label;\n        this._values = values;\n    }\n\n    /**\n     * The default type of series.\n     *\n     * @type {Null}\n     * @const\n     */\n    Series.prototype.TYPE_DEFAULT = null;\n\n    /**\n     * Type of series 'line'.\n     *","sourceCodeStart":22,"sourceCodeEnd":58,"githubUrl":"https://github.com/moodle/moodle/blob/48ea8c33227277e916cdd4079dbecef448b37f2c/public/lib/amd/src/chart_series.js#L22-L58","documentation":"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.","triggerScenarios":"new Series('label', []) — an array with length 0.","commonSituations":"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.","solutions":["Ensure the values array has at least one element before constructing the series.","Guard the chart-build code: skip or defer rendering when the dataset is empty.","Fix upstream data fetching/filtering so the array is populated."],"exampleFix":"// before\nconst series = new Series('Sales', records.filter(r => r.valid)); // may be []\n// after\nconst valid = records.filter(r => r.valid);\nif (valid.length === 0) return;\nconst series = new Series('Sales', valid);","handlingStrategy":"validation","validationCode":"if (!Array.isArray(values) || values.length < 1) {\n    throw new TypeError('Series values must be a non-empty array');\n}\nconst series = new Series(label, values);","typeGuard":"function isNonEmptyArray(v) { return Array.isArray(v) && v.length > 0; }","tryCatchPattern":"try {\n    const series = new Series(label, values);\n} catch (e) {\n    if (e.message === 'Invalid values received for series.') {\n        return null; // skip chart with no data\n    }\n    throw e;\n}","preventionTips":["Guard against empty datasets before rendering (return early if data.length === 0).","Ensure async data has loaded before building the chart.","Test chart code with empty filter results."],"tags":["javascript","validation","empty-array","constructor"],"backgroundTag":"empty-required-field","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"}