BabylonJS/Babylon.js · error

Unable to save your ${entityName ?? "content"}: ${e}

Error message

Unable to save your ${entityName ?? "content"}: ${e}

What it means

SaveToSnippetServer wraps the fetch() POST to the snippet server in a try/catch; if the network request itself throws (never reaches an HTTP response), it builds this message including the underlying error text, calls alert(), and rethrows with the original error as `cause`. It exists to tell the user which entity type (e.g. 'particle system') failed to save while preserving the root cause (network failure, CORS, invalid URL, server unreachable).

Source

Thrown at packages/dev/inspector-v2/src/misc/snippetUtils.ts:82

        name: "",
        description: "",
        tags: "",
    };

    const headers = new Headers();
    headers.append("Content-Type", "application/json");

    let response: Response;
    try {
        response = await fetch(snippetUrl + (currentSnippetId ? "/" + currentSnippetId : ""), {
            method: "POST",
            headers,
            body: JSON.stringify(dataToSend),
        });
    } catch (e) {
        const errorMsg = `Unable to save your ${entityName ?? "content"}: ${e}`;
        alert(errorMsg);
        throw new Error(errorMsg, { cause: e });
    }

    if (!response.ok) {
        const errorMsg = `Unable to save your ${entityName ?? "content"}`;
        alert(errorMsg);
        throw new Error(errorMsg);
    }

    const snippet = await response.json();
    const oldSnippetId = currentSnippetId || "_BLANK";
    let newSnippetId = snippet.id;
    if (snippet.version && snippet.version !== "0") {
        newSnippetId += "#" + snippet.version;
    }

    // Copy to clipboard when available.
    if (navigator.clipboard) {
        await navigator.clipboard.writeText(newSnippetId);

View on GitHub (pinned to 0592b347b8)

Solutions

  1. Verify the snippet server is running and that config.snippetUrl points at the correct host/port/protocol (https on https pages).
  2. Open the browser console/network tab and inspect `e` (the Error.cause) to see if it is CORS, DNS, or a connection refusal, and fix that root cause.
  3. If self-hosting the snippet server, enable CORS headers for the page origin.
  4. Add retry logic or a health check against snippetUrl before invoking save.
  5. If you only need local persistence, bypass the server and store the content via localStorage instead.

Example fix

// before: fails silently into alert when server is down
await SaveToSnippetServer({ snippetUrl: "http://localhost:1338", content, payloadKey: "particleSystem" });

// after: probe server first and fall back
async function saveSnippet(config) {
  try {
    await fetch(config.snippetUrl, { method: "HEAD" });
  } catch {
    localStorage.setItem("snippet-backup", config.content);
    throw new Error("Snippet server unreachable; content backed up locally");
  }
  return SaveToSnippetServer(config);
}
Defensive patterns

Strategy: try-catch

Validate before calling

async function assertSnippetServerReady(snippetUrl) {
  const u = new URL(snippetUrl);
  if (window.location.protocol === "https:" && u.protocol !== "https:") {
    throw new Error("Mixed content: snippet server must use https");
  }
  await fetch(snippetUrl, { method: "HEAD" });
}

Try / catch

try {
  const result = await SaveToSnippetServer(config);
} catch (e) {
  console.error("Snippet save failed:", e.cause ?? e);
  // e.cause holds the original fetch error (CORS, DNS, offline)
  localStorage.setItem("snippet-backup:" + config.payloadKey, config.content);
}

Prevention

When it happens

Trigger: Calling SaveToSnippetServer when fetch() rejects: snippet server host unreachable or offline, invalid/incorrect snippetUrl (bad protocol, typo, mixed HTTP/HTTPS content blocking), CORS rejection, browser offline, DNS failure, or the request aborted before a Response is produced.

Common situations: Running the inspector against a locally started snippet server that is not running yet; a snippetUrl with a trailing typo or wrong port; CORS not enabled on a self-hosted snippet server; corporate proxy/firewall blocking the request; testing in an environment without network access.

Related errors


AI-assisted analysis of BabylonJS/Babylon.js@0592b347b8 (2026-08-30). Data as JSON: /api/errors/70398bcb6206c14c. Report an issue: GitHub.