{"record":{"id":"bc90bc476444ae09","repo":"louislam/uptime-kuma","slug":"invalid-period","errorCode":null,"errorMessage":"Invalid period.","messagePattern":"Invalid period\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"warning","filePath":"server/server.js","lineNumber":1060,"sourceCode":"                });\n            } catch (e) {\n                callback({\n                    ok: false,\n                    msg: e.message,\n                    msgi18n: !!e.msgi18n,\n                    meta: e.meta ?? {},\n                });\n            }\n        });\n\n        socket.on(\"getMonitorBeats\", async (monitorID, period, callback) => {\n            try {\n                checkLogin(socket);\n\n                log.info(\"monitor\", `Get Monitor Beats: ${monitorID} User ID: ${socket.userID}`);\n\n                if (period == null) {\n                    throw new Error(\"Invalid period.\");\n                }\n\n                const sqlHourOffset = Database.sqlHourOffset();\n\n                let list = await R.getAll(\n                    `\n                    SELECT *\n                    FROM heartbeat\n                    WHERE monitor_id = ?\n                      AND time > ${sqlHourOffset}\n                    ORDER BY time ASC\n                `,\n                    [monitorID, -period]\n                );\n\n                callback({\n                    ok: true,\n                    data: list,","sourceCodeStart":1042,"sourceCodeEnd":1078,"githubUrl":"https://github.com/louislam/uptime-kuma/blob/6b5ea0155793e666666745fb8d6fef1e829543a2/server/server.js#L1042-L1078","documentation":"Thrown by the 'getMonitorBeats' socket handler when the `period` argument is null or undefined (checked with `period == null`, so both null and undefined trigger it). `period` is the second argument to the event and is used as a negative hour offset in the heartbeat SQL query.","triggerScenarios":"A client emits 'getMonitorBeats' omitting the period argument, or explicitly passing null/undefined. The handler needs a numeric period (in hours) to bound the query.","commonSituations":"Frontend component calls getMonitorBeats(monitorID) without the period; a date-range selector defaults to null; refactor dropped the second argument.","solutions":["Always pass a numeric period (hours) as the second argument, e.g. getMonitorBeats(monitorID, 24).","Default the period in the caller when the date-range selector is empty.","Validate the period is a positive number before emitting.","Handle the {ok:false} callback by retrying with a sane default period."],"exampleFix":"// before\nsocket.emit('getMonitorBeats', monitorID, cb);\n\n// after\nconst period = selectedHours ?? 24;\nsocket.emit('getMonitorBeats', monitorID, period, cb);","handlingStrategy":"validation","validationCode":"// Always pass a numeric period (hours); default when unset\nconst period = Number(selectedHours);\nif (!Number.isFinite(period) || period <= 0) {\n  return setError('Select a valid time range.');\n}\nsocket.emit('getMonitorBeats', monitorID, period, cb);","typeGuard":"function isValidPeriod(period) {\n  return typeof period === 'number' && Number.isFinite(period) && period > 0;\n}","tryCatchPattern":null,"preventionTips":["Always pass a positive numeric period as the second argument.","Default the period when the date-range selector is empty.","Validate the period before emitting the event.","On {ok:false}, retry with a sane default period."],"tags":["monitor","heartbeat","validation","socket","missing-argument"],"backgroundTag":null,"analyzedSha":"6b5ea0155793e666666745fb8d6fef1e829543a2","analyzedAt":"2026-08-12T23:42:12.959Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}