louislam/uptime-kuma · warning · Error
Slug must be string
Error message
Slug must be string
What it means
Thrown by checkSlug() inside the status-page socket handler. The function guards its first branch with `typeof slug !== "string"`, so any non-string value (number, boolean, array, object, null, undefined) is rejected before slug formatting rules run. It exists because slug values are used directly in SQL queries (R.findOne("status_page", " slug = ? ", [slug])) and as URL path segments, where a non-string would corrupt downstream logic.
Source
Thrown at server/socket-handlers/status-page-socket-handler.js:535
} catch (error) {
callback({
ok: false,
msg: error.message,
});
}
});
};
/**
* Check slug a-z, 0-9, - only
* Regex from: https://stackoverflow.com/questions/22454258/js-regex-string-validation-for-slug
* @param {string} slug Slug to test
* @returns {void}
* @throws Slug is not valid
*/
function checkSlug(slug) {
if (typeof slug !== "string") {
throw new Error("Slug must be string");
}
slug = slug.trim();
if (!slug) {
throw new Error("Slug cannot be empty");
}
if (!slug.match(/^[A-Za-z0-9]+(?:-[A-Za-z0-9]+)*$/)) {
throw new Error("Invalid Slug");
}
}
View on GitHub (pinned to 6b5ea01557)
Solutions
- Ensure config.slug is a string before emitting saveStatusPage: `String(config.slug)`.
- Validate the slug client-side with the same regex `^[A-Za-z0-9]+(?:-[A-Za-z0-9]+)*$` before submission.
- If you operate the socket programmatically, double-check the payload shape against the handler signature: (slug, config, imgDataUrl, publicGroupList, callback).
- Add a typeof guard in your caller so an empty/missing slug short-circuits with a user-friendly message instead of reaching the server.
Example fix
// before
socket.emit("saveStatusPage", slug, { slug: 123, title }, ...);
// after
const safeSlug = typeof config.slug === "string" ? config.slug : String(config.slug ?? "");
socket.emit("saveStatusPage", slug, { ...config, slug: safeSlug }, ...); Defensive patterns
Strategy: type-guard
Validate before calling
function isStringSlug(v) { return typeof v === "string"; }
if (!isStringSlug(config.slug)) { throw new TypeError("slug must be a string"); }
checkSlug(config.slug); Type guard
const isString = (v) => typeof v === "string";
Try / catch
try { checkSlug(config.slug); } catch (e) { callback({ ok: false, msg: e.message }); return; } Prevention
- Always stringify the slug at the source before building the socket payload.
- Keep a single slugify/isStringSlug helper shared by create and save paths.
- Type the payload in TS so a non-string slug fails at compile time.
When it happens
Trigger: Emitting the socket event `saveStatusPage(slug, config, imgDataUrl, publicGroupList, callback)` with a `config.slug` that is not a string (e.g. a number, null, undefined, or object). checkSlug is invoked at status-page-socket-handler.js:303 on `config.slug`. The `createStatusPage` path (line 456) pre-checks `typeof slug !== "string"` with a different message ("Slug -Accept string only"), so this specific message is reached only via saveStatusPage.
Common situations: A custom/programmatic socket client that omits slug or sends it as a number; a frontend regression where the slug input binds to a numeric model; corrupt status page config loaded from storage; an integration test that passes a raw number instead of a stringified slug.
Related errors
AI-assisted analysis of louislam/uptime-kuma@6b5ea01557 (2026-08-12).
Data as JSON: /api/errors/c51720beade8f300.
Report an issue: GitHub.