{"record":{"id":"6bf5d4ac8bbc8e93","repo":"louislam/uptime-kuma","slug":"unsupported-unit-unit-for-badge-duration-du","errorCode":null,"errorMessage":"Unsupported unit (${unit}) for badge duration ${duration}","messagePattern":"Unsupported unit \\((.+?)\\) for badge duration (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"warning","filePath":"server/uptime-calculator.js","lineNumber":798,"sourceCode":"        }\n        const num = Number(durationNumStr);\n        const unit = duration.slice(-1);\n\n        switch (unit) {\n            case \"m\":\n                return this.getData(num, \"minute\");\n            case \"h\":\n                return this.getData(num, \"hour\");\n            case \"d\":\n                return this.getData(num, \"day\");\n            case \"w\":\n                return this.getData(7 * num, \"day\");\n            case \"M\":\n                return this.getData(30 * num, \"day\");\n            case \"y\":\n                return this.getData(365 * num, \"day\");\n            default:\n                throw new Error(`Unsupported unit (${unit}) for badge duration ${duration}`);\n        }\n    }\n\n    /**\n     * 1440 = 24 * 60mins\n     * @returns {UptimeDataResult} UptimeDataResult\n     */\n    get24Hour() {\n        return this.getData(1440, \"minute\");\n    }\n\n    /**\n     * @returns {UptimeDataResult} UptimeDataResult\n     */\n    get7Day() {\n        return this.getData(168, \"hour\");\n    }\n","sourceCodeStart":780,"sourceCodeEnd":816,"githubUrl":"https://github.com/louislam/uptime-kuma/blob/6b5ea0155793e666666745fb8d6fef1e829543a2/server/uptime-calculator.js#L780-L816","documentation":"Thrown by getDataByDuration's switch on the trailing unit character when it is not one of m/h/d/w/M/y. Note the units are case-sensitive: \"M\" (capital) is month, \"m\" is minute, \"h\" is hour, \"d\" is day, \"w\" is week, \"y\" is year. \"H\", \"S\", \"s\", \"D\" etc. all fall through to default.","triggerScenarios":"getDataByDuration(\"24s\"), \"24H\" (capital H — seconds and capital-hour are unsupported), \"24D\", \"24x\", or any duration whose last char is outside the supported set. Badge URL `/api/badge/:id/status/30S`.","commonSituations":"User assumes SI-style units (s for seconds, uppercase H for hour); typographical error in the unit; a duration string copied from a different system (ISO-8601 \"PT24H\"); confusion that \"M\" is month while \"m\" is minute.","solutions":["Use only the supported units: m (minute), h (hour), d (day), w (week), M (month, capital), y (year).","Validate with `/^(\\d+)([mhdwMy])$/` before calling and surface the allowed set to the user.","If accepting user input, normalize common aliases (s/seconds, H/hour) to the canonical letter.","Document the case-sensitivity of M (month) vs m (minute) prominently."],"exampleFix":"// before\nconst up = uptimeCalculator.getDataByDuration(\"24H\"); // H unsupported -> throws\n\n// after\nconst up = uptimeCalculator.getDataByDuration(\"24h\"); // lowercase h\n// month vs minute:\n// \"1M\" -> 30 days (month), \"1m\" -> 1 minute","handlingStrategy":"validation","validationCode":"const UNITS = new Set([\"m\",\"h\",\"d\",\"w\",\"M\",\"y\"]);\nconst u = duration.slice(-1);\nif (!UNITS.has(u)) throw new Error(\"Unsupported unit \" + u);","typeGuard":"const hasSupportedUnit = (v) => typeof v === \"string\" && /^[mhdwMy]$/.test(v.slice(-1));","tryCatchPattern":"try { getDataByDuration(d); } catch (e) { if (/Unsupported unit/.test(e.message)) { /* map alias e.g. s->m, H->h */ } throw e; }","preventionTips":["Use only m, h, d, w, M (month, capital), y.","Remember M is month, m is minute — case matters.","Normalize common aliases (s, H, D) to canonical units before calling."],"tags":["uptime-calculator","duration","units","validation","uptime-kuma"],"backgroundTag":null,"analyzedSha":"6b5ea0155793e666666745fb8d6fef1e829543a2","analyzedAt":"2026-08-12T23:42:12.959Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}