louislam/uptime-kuma · warning · Error

Invalid period.

Error message

Invalid period.

What it means

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.

Source

Thrown at server/socket-handlers/chart-socket-handler.js:13

const { checkLogin } = require("../util-server");
const { UptimeCalculator } = require("../uptime-calculator");
const { log } = require("../../src/util");

module.exports.chartSocketHandler = (socket) => {
    socket.on("getMonitorChartData", async (monitorID, period, callback) => {
        try {
            checkLogin(socket);

            log.debug("monitor", `Get Monitor Chart Data: ${monitorID} User ID: ${socket.userID}`);

            if (period == null) {
                throw new Error("Invalid period.");
            }

            let uptimeCalculator = await UptimeCalculator.getUptimeCalculator(monitorID);

            let data;
            if (period <= 24) {
                data = uptimeCalculator.getDataArray(period * 60, "minute");
            } else if (period <= 720) {
                data = uptimeCalculator.getDataArray(period, "hour");
            } else {
                data = uptimeCalculator.getDataArray(period / 24, "day");
            }

            callback({
                ok: true,
                data,
            });
        } catch (e) {

View on GitHub (pinned to 6b5ea01557)

Solutions

  1. Pass a concrete numeric period (e.g. 24, 720, 1440) as the second argument to getMonitorChartData.
  2. On the client, guard the emit so it only fires once a valid period value is selected.
  3. If the UI default changed, restore a default period before the first emit.

Example fix

// before
socket.emit("getMonitorChartData", monitorID, undefined, cb);
// after
socket.emit("getMonitorChartData", monitorID, 24, cb);
Defensive patterns

Strategy: type-guard

Validate before calling

function validPeriod(p) {
  return typeof p === "number" && Number.isFinite(p) && p > 0;
}
if (!validPeriod(period)) throw new Error("period must be a positive number");
socket.emit("getMonitorChartData", monitorID, period, cb);

Type guard

function isPeriod(v) {
  return typeof v === "number" && Number.isFinite(v) && v > 0;
}

Try / catch

socket.on("getMonitorChartData", (id, period, cb) => {
  if (period == null) return cb({ ok: false, msg: "Invalid period." });
  // proceed
});

Prevention

When it happens

Trigger: 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.

Common situations: 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).

Related errors


AI-assisted analysis of louislam/uptime-kuma@6b5ea01557 (2026-08-12). Data as JSON: /api/errors/7aca5e4779a9c26a. Report an issue: GitHub.