louislam/uptime-kuma · warning · Error

Invalid period.

Error message

Invalid period.

What it means

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.

Source

Thrown at server/server.js:1060

                });
            } catch (e) {
                callback({
                    ok: false,
                    msg: e.message,
                    msgi18n: !!e.msgi18n,
                    meta: e.meta ?? {},
                });
            }
        });

        socket.on("getMonitorBeats", async (monitorID, period, callback) => {
            try {
                checkLogin(socket);

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

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

                const sqlHourOffset = Database.sqlHourOffset();

                let list = await R.getAll(
                    `
                    SELECT *
                    FROM heartbeat
                    WHERE monitor_id = ?
                      AND time > ${sqlHourOffset}
                    ORDER BY time ASC
                `,
                    [monitorID, -period]
                );

                callback({
                    ok: true,
                    data: list,

View on GitHub (pinned to 6b5ea01557)

Solutions

  1. Always pass a numeric period (hours) as the second argument, e.g. getMonitorBeats(monitorID, 24).
  2. Default the period in the caller when the date-range selector is empty.
  3. Validate the period is a positive number before emitting.
  4. Handle the {ok:false} callback by retrying with a sane default period.

Example fix

// before
socket.emit('getMonitorBeats', monitorID, cb);

// after
const period = selectedHours ?? 24;
socket.emit('getMonitorBeats', monitorID, period, cb);
Defensive patterns

Strategy: validation

Validate before calling

// Always pass a numeric period (hours); default when unset
const period = Number(selectedHours);
if (!Number.isFinite(period) || period <= 0) {
  return setError('Select a valid time range.');
}
socket.emit('getMonitorBeats', monitorID, period, cb);

Type guard

function isValidPeriod(period) {
  return typeof period === 'number' && Number.isFinite(period) && period > 0;
}

Prevention

When it happens

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

Common situations: Frontend component calls getMonitorBeats(monitorID) without the period; a date-range selector defaults to null; refactor dropped the second argument.

Related errors


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