{"record":{"id":"7aca5e4779a9c26a","repo":"louislam/uptime-kuma","slug":"invalid-period-7aca5e","errorCode":null,"errorMessage":"Invalid period.","messagePattern":"Invalid period\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"warning","filePath":"server/socket-handlers/chart-socket-handler.js","lineNumber":13,"sourceCode":"const { checkLogin } = require(\"../util-server\");\nconst { UptimeCalculator } = require(\"../uptime-calculator\");\nconst { log } = require(\"../../src/util\");\n\nmodule.exports.chartSocketHandler = (socket) => {\n    socket.on(\"getMonitorChartData\", async (monitorID, period, callback) => {\n        try {\n            checkLogin(socket);\n\n            log.debug(\"monitor\", `Get Monitor Chart Data: ${monitorID} User ID: ${socket.userID}`);\n\n            if (period == null) {\n                throw new Error(\"Invalid period.\");\n            }\n\n            let uptimeCalculator = await UptimeCalculator.getUptimeCalculator(monitorID);\n\n            let data;\n            if (period <= 24) {\n                data = uptimeCalculator.getDataArray(period * 60, \"minute\");\n            } else if (period <= 720) {\n                data = uptimeCalculator.getDataArray(period, \"hour\");\n            } else {\n                data = uptimeCalculator.getDataArray(period / 24, \"day\");\n            }\n\n            callback({\n                ok: true,\n                data,\n            });\n        } catch (e) {","sourceCodeStart":1,"sourceCodeEnd":31,"githubUrl":"https://github.com/louislam/uptime-kuma/blob/6b5ea0155793e666666745fb8d6fef1e829543a2/server/socket-handlers/chart-socket-handler.js#L1-L31","documentation":"Thrown by the getMonitorChartData socket handler when the period argument is null/undefined. The handler then branches on numeric ranges of period (<=24, <=720, else) to pick minute/hour/day aggregation, so a missing period is unrecoverable.","triggerScenarios":"Client emits 'getMonitorChartData' with monitorID and a null/undefined period, or omits the second argument so it arrives as undefined. The check fires after checkLogin.","commonSituations":"Frontend sends period only after a UI control loads and the chart requests data before that; a refactor changed the event signature; client passes period as a string that the loose == null check does not catch (note == null only catches null/undefined).","solutions":["Pass a concrete numeric period (e.g. 24, 720, 1440) as the second argument to getMonitorChartData.","On the client, guard the emit so it only fires once a valid period value is selected.","If the UI default changed, restore a default period before the first emit."],"exampleFix":"// before\nsocket.emit(\"getMonitorChartData\", monitorID, undefined, cb);\n// after\nsocket.emit(\"getMonitorChartData\", monitorID, 24, cb);","handlingStrategy":"type-guard","validationCode":"function validPeriod(p) {\n  return typeof p === \"number\" && Number.isFinite(p) && p > 0;\n}\nif (!validPeriod(period)) throw new Error(\"period must be a positive number\");\nsocket.emit(\"getMonitorChartData\", monitorID, period, cb);","typeGuard":"function isPeriod(v) {\n  return typeof v === \"number\" && Number.isFinite(v) && v > 0;\n}","tryCatchPattern":"socket.on(\"getMonitorChartData\", (id, period, cb) => {\n  if (period == null) return cb({ ok: false, msg: \"Invalid period.\" });\n  // proceed\n});","preventionTips":["Default period to a number on the client before first emit.","Pass period as a number, not a stringified value.","Gate the chart request on UI state being fully loaded."],"tags":["chart","validation","socket-io","uptime-calculator"],"backgroundTag":null,"analyzedSha":"6b5ea0155793e666666745fb8d6fef1e829543a2","analyzedAt":"2026-08-12T23:42:12.959Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}