{"record":{"id":"7c5589abc24cd4ef","repo":"louislam/uptime-kuma","slug":"monitor-id-is-required","errorCode":null,"errorMessage":"Monitor ID is required","messagePattern":"Monitor ID is required","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"server/uptime-calculator.js","lineNumber":74,"sourceCode":"\n    /**\n     * For migration purposes.\n     * @type {boolean}\n     */\n    migrationMode = false;\n\n    statMinutelyKeepHour = 24;\n    statHourlyKeepDay = 30;\n\n    /**\n     * Get the uptime calculator for a monitor\n     * Initializes and returns the monitor if it does not exist\n     * @param {number} monitorID the id of the monitor\n     * @returns {Promise<UptimeCalculator>} UptimeCalculator\n     */\n    static async getUptimeCalculator(monitorID) {\n        if (!monitorID) {\n            throw new Error(\"Monitor ID is required\");\n        }\n\n        if (!UptimeCalculator.list[monitorID]) {\n            UptimeCalculator.list[monitorID] = new UptimeCalculator();\n            await UptimeCalculator.list[monitorID].init(monitorID);\n        }\n        return UptimeCalculator.list[monitorID];\n    }\n\n    /**\n     * Remove a monitor from the list\n     * @param {number} monitorID the id of the monitor\n     * @returns {Promise<void>}\n     */\n    static async remove(monitorID) {\n        delete UptimeCalculator.list[monitorID];\n    }\n","sourceCodeStart":56,"sourceCodeEnd":92,"githubUrl":"https://github.com/louislam/uptime-kuma/blob/6b5ea0155793e666666745fb8d6fef1e829543a2/server/uptime-calculator.js#L56-L92","documentation":"Thrown by UptimeCalculator.getUptimeCalculator(monitorID) when `!monitorID` is truthy — i.e. monitorID is undefined, null, 0, NaN, or empty string. The calculator must key its in-memory cache (`UptimeCalculator.list[monitorID]`) and persist per-monitor statistics, so a missing ID is a hard stop, not a fallback.","triggerScenarios":"Called from api-router.js:92/257/317 (badge/status/ping endpoints), status-page-router.js:99, monitor.js:1053/1317, or chart-socket-handler.js:16 with a monitorID that parseInt failed on, a monitor row whose id is 0/null, or a monitor object whose `this.id` is not yet assigned (unsaved bean). For example, `parseInt(request.params.id, 10)` returning NaN is guarded upstream in some routes but not all.","commonSituations":"Requesting `/api/badge/abc/status` where abc is non-numeric and the route did not pre-validate; calling monitor.stop() or getUptimeCalculator during a half-initialized monitor; a status page referencing a deleted monitor id stored as null; race condition where monitor.id is read before R.store assigns it.","solutions":["Validate and parse the monitor id at the trust boundary before lookup: `const id = Number(monitorID); if (!Number.isInteger(id) || id <= 0) return;`.","Ensure the monitor bean is stored (has an id) before any uptime-calculator call.","In routes, return 400/404 early when the id param is non-numeric instead of reaching the calculator.","Filter status page monitor lists for null ids before iterating."],"exampleFix":"// before\nconst uc = await UptimeCalculator.getUptimeCalculator(monitor.id);\n\n// after\nif (!Number.isInteger(monitor.id) || monitor.id <= 0) {\n  throw new Error(\"Monitor not persisted\");\n}\nconst uc = await UptimeCalculator.getUptimeCalculator(monitor.id);","handlingStrategy":"validation","validationCode":"const id = Number(monitorID);\nif (!Number.isInteger(id) || id <= 0) { throw new Error(\"Valid monitor id required\"); }\nawait UptimeCalculator.getUptimeCalculator(id);","typeGuard":"const isPositiveInt = (v) => Number.isInteger(Number(v)) && Number(v) > 0;","tryCatchPattern":"try { await UptimeCalculator.getUptimeCalculator(monitorID); } catch (e) { if (e.message === \"Monitor ID is required\") return null; throw e; }","preventionTips":["Parse and validate the id at every route/entry boundary.","Ensure monitor beans are stored (id assigned) before referencing them.","Filter out null/0 monitor ids when iterating status-page monitor lists."],"tags":["uptime-calculator","monitor","validation","api","uptime-kuma"],"backgroundTag":null,"analyzedSha":"6b5ea0155793e666666745fb8d6fef1e829543a2","analyzedAt":"2026-08-12T23:42:12.959Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}