louislam/uptime-kuma · warning · Error

Invalid Slug

Error message

Invalid Slug

What it means

Thrown by checkSlug() when the slug fails the regex `^[A-Za-z0-9]+(?:-[A-Za-z0-9]+)*$`. Allowed: one or more alphanumerics, optionally followed by groups of a single hyphen plus alphanumerics. Forbidden: underscores, dots, slashes, spaces, leading/trailing hyphens, consecutive hyphens. The slug becomes the public URL path of a status page, so it must be URL-safe and unambiguous.

Source

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

 * 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. Sanitize the slug to the allowed charset before submitting: lowercase, replace any non-alphanumeric run with a single hyphen, trim leading/trailing hyphens.
  2. Show live regex feedback in the editor so the user sees the rule before submit.
  3. Reuse a shared slugify helper for both create and save paths.
  4. Document the slug rule on the input field: 'Letters, numbers, and single hyphens only.'

Example fix

// before
const slug = "My_Status_Page";

// after
function slugify(input) {
  return String(input)
    .trim()
    .replace(/[^A-Za-z0-9]+/g, "-")
    .replace(/^-+|-+$/g, "");
}
const slug = slugify("My_Status_Page"); // "My-Status-Page"
Defensive patterns

Strategy: validation

Validate before calling

const SLUG_RE = /^[A-Za-z0-9]+(?:-[A-Za-z0-9]+)*$/;
if (!SLUG_RE.test(slug)) { throw new Error("Slug must be letters, numbers, single hyphens"); }

Type guard

const isValidSlug = (v) => typeof v === "string" && /^[A-Za-z0-9]+(?:-[A-Za-z0-9]+)*$/.test(v);

Try / catch

try { checkSlug(slug); } catch (e) { if (e.message === "Invalid Slug") showFieldError("slug", e.message); else throw e; }

Prevention

When it happens

Trigger: saveStatusPage (or createStatusPage) with a slug containing `_`, `.`, `/`, ` `, capital-only is fine but any special character fails; slugs like "my page", "my_page", "-lead", "double--hyphen", "trailing-", "api/v2" all throw. Note createStatusPage lowercases first (line 454) but the regex itself is case-insensitive via A-Za-z, so case is not the cause.

Common situations: User copies a slug from a CMS that allows underscores; attempt to nest status pages with slashes; trailing hyphen from auto-generating slug from a title ending in a dash; migration from a system with different slug rules.

Related errors


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