louislam/uptime-kuma · warning · Error
Unsupported unit (${unit}) for badge duration ${duration}
Error message
Unsupported unit (${unit}) for badge duration ${duration} What it means
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.
Source
Thrown at server/uptime-calculator.js:798
}
const num = Number(durationNumStr);
const unit = duration.slice(-1);
switch (unit) {
case "m":
return this.getData(num, "minute");
case "h":
return this.getData(num, "hour");
case "d":
return this.getData(num, "day");
case "w":
return this.getData(7 * num, "day");
case "M":
return this.getData(30 * num, "day");
case "y":
return this.getData(365 * num, "day");
default:
throw new Error(`Unsupported unit (${unit}) for badge duration ${duration}`);
}
}
/**
* 1440 = 24 * 60mins
* @returns {UptimeDataResult} UptimeDataResult
*/
get24Hour() {
return this.getData(1440, "minute");
}
/**
* @returns {UptimeDataResult} UptimeDataResult
*/
get7Day() {
return this.getData(168, "hour");
}
View on GitHub (pinned to 6b5ea01557)
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.
Example fix
// before
const up = uptimeCalculator.getDataByDuration("24H"); // H unsupported -> throws
// after
const up = uptimeCalculator.getDataByDuration("24h"); // lowercase h
// month vs minute:
// "1M" -> 30 days (month), "1m" -> 1 minute Defensive patterns
Strategy: validation
Validate before calling
const UNITS = new Set(["m","h","d","w","M","y"]);
const u = duration.slice(-1);
if (!UNITS.has(u)) throw new Error("Unsupported unit " + u); Type guard
const hasSupportedUnit = (v) => typeof v === "string" && /^[mhdwMy]$/.test(v.slice(-1));
Try / catch
try { getDataByDuration(d); } catch (e) { if (/Unsupported unit/.test(e.message)) { /* map alias e.g. s->m, H->h */ } throw e; } Prevention
- 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.
When it happens
Trigger: 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`.
Common situations: 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.
Related errors
- Invalid duration: ${duration}
- Monitor ID is required
- The maximum number of hours is 720
- The maximum number of minutes is 1440
- The maximum number of days is 365
AI-assisted analysis of louislam/uptime-kuma@6b5ea01557 (2026-08-12).
Data as JSON: /api/errors/6bf5d4ac8bbc8e93.
Report an issue: GitHub.