louislam/uptime-kuma · warning · Error

Slug cannot be empty

Error message

Slug cannot be empty

What it means

Thrown by checkSlug() after `slug = slug.trim()` when the trimmed result is falsy (empty string). It is the second validation gate, ensuring the slug is not blank before the regex check. Required because an empty slug would create an unreachable status page route and would conflict with reserved paths.

Source

Thrown at server/socket-handlers/status-page-socket-handler.js:541

    });
};

/**
 * 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

  1. Make the slug field required on the client and disable submit while it is empty or whitespace-only.
  2. Trim and reject empty slugs before emitting: `if (!String(config.slug).trim()) return;`.
  3. If importing/migrating status pages, generate a fallback slug from the title (lowercased, hyphenated) when blank.
  4. Audit stored status_page rows for empty slug values: `SELECT * FROM status_page WHERE slug IS NULL OR trim(slug) = ''`.

Example fix

// before
socket.emit("saveStatusPage", slug, { slug: "   ", title: "My Page" }, ...);

// after
const slugVal = String(config.slug ?? "").trim();
if (!slugVal) { alert("Slug is required"); return; }
socket.emit("saveStatusPage", slug, { ...config, slug: slugVal }, ...);
Defensive patterns

Strategy: validation

Validate before calling

const slug = typeof config.slug === "string" ? config.slug.trim() : "";
if (!slug) { callback({ ok: false, msg: "Slug is required" }); return; }

Type guard

const isNonEmptyString = (v) => typeof v === "string" && v.trim().length > 0;

Try / catch

try { checkSlug(slug); } catch (e) { if (e.message === "Slug cannot be empty") { /* prompt user */ } throw e; }

Prevention

When it happens

Trigger: saveStatusPage emitted with `config.slug` equal to "", " " (whitespace only), or a value that trims to empty. Also reachable from createStatusPage (line 456) if the earlier `!slug` check at line 444 is bypassed, but normally line 444 throws "Please input all fields" first.

Common situations: User clears the slug field in the status page editor but the form still submits; whitespace-only slug pasted from clipboard; frontend form validation disabled or skipped; a migration/import script that writes status pages with blank slugs.

Related errors


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