{"record":{"id":"616da10f55fb495b","repo":"ankane/pghero","slug":"nouislider-invalid-handle-number-got-handlenum","errorCode":null,"errorMessage":"noUiSlider: invalid handle number, got: {handleNumber}","messagePattern":"noUiSlider: invalid handle number, got: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"app/assets/javascripts/pghero/nouislider.js","lineNumber":2087,"sourceCode":"            setZindex();\n            scope_HandleNumbers.forEach(function (handleNumber) {\n                fireEvent(\"update\", handleNumber);\n                // Fire the event only for handles that received a new value, as per #579\n                if (values[handleNumber] !== null && fireSetEvent) {\n                    fireEvent(\"set\", handleNumber);\n                }\n            });\n        }\n        // Reset slider to initial values\n        function valueReset(fireSetEvent) {\n            valueSet(options.start, fireSetEvent);\n        }\n        // Set value for a single handle\n        function valueSetHandle(handleNumber, value, fireSetEvent, exactInput) {\n            // Ensure numeric input\n            handleNumber = Number(handleNumber);\n            if (!(handleNumber >= 0 && handleNumber < scope_HandleNumbers.length)) {\n                throw new Error(\"noUiSlider: invalid handle number, got: \" + handleNumber);\n            }\n            // Look both backward and forward, since we don't want this handle to \"push\" other handles (#960);\n            // The exactInput argument can be used to ignore slider stepping (#436)\n            setHandle(handleNumber, resolveToValue(value, handleNumber), true, true, exactInput);\n            fireEvent(\"update\", handleNumber);\n            if (fireSetEvent) {\n                fireEvent(\"set\", handleNumber);\n            }\n        }\n        // Get the slider value.\n        function valueGet(unencoded) {\n            if (unencoded === void 0) { unencoded = false; }\n            if (unencoded) {\n                // return a copy of the raw values\n                return scope_Values.length === 1 ? scope_Values[0] : scope_Values.slice(0);\n            }\n            var values = scope_Values.map(options.format.to);\n            // If only one handle is used, return a single value.","sourceCodeStart":2069,"sourceCodeEnd":2105,"githubUrl":"https://github.com/ankane/pghero/blob/7edb57986ffd36f9d64f0830c4ccc90a5eac46d6/app/assets/javascripts/pghero/nouislider.js#L2069-L2105","documentation":"valueSetHandle() coerces the handle number with Number() and requires 0 <= handleNumber < scope_HandleNumbers.length (the number of handles created from the start option). API calls that address a single handle - chiefly noUiSlider.setHandle(handleNumber, value) - throw this Error when the index does not exist, including the NaN case from non-numeric input.","triggerScenarios":"A slider created with start: [50] (one handle) followed by slider.noUiSlider.setHandle(1, 80); an index computed from data attributes or loops that goes past handle count - 1; passing undefined (Number(undefined) is NaN, which fails the range check).","commonSituations":"Handle count varies with configuration (start array length changes) while calling code hardcodes indices; off-by-one loops over handles; saved UI state (per-handle positions) replayed onto a slider that now has fewer handles.","solutions":["Check the live handle count before setting: slider.noUiSlider.get().length is the number of handles","Use set() with an array matching the start configuration instead of setHandle when targeting all handles","Make the handle count explicit in one place and derive both start and any setHandle indices from it"],"exampleFix":"// before - slider has one handle but index 1 requested\nslider.noUiSlider.setHandle(1, 50);\n\n// after - guard against the handle count\nif (index < slider.noUiSlider.get().length) {\n  slider.noUiSlider.setHandle(index, 50);\n}","handlingStrategy":"validation","validationCode":"const handleCount = slider.noUiSlider.get().length; // works for 1..n handles\nif (handleNumber >= 0 && handleNumber < handleCount) {\n  slider.noUiSlider.setHandle(handleNumber, value);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Derive handle indices from the start array length instead of hardcoding them","Prefer set([...]) with the full array over setHandle when handle count may change"],"tags":["nouislider","handle","index-out-of-range","javascript"],"backgroundTag":"index-out-of-bounds","analyzedSha":"7edb57986ffd36f9d64f0830c4ccc90a5eac46d6","analyzedAt":"2026-08-21T17:33:54.942Z","schemaVersion":2},"datasetVersion":"2026-08-21T18:17:14.833Z"}