wavetermdev/waveterm · error

Invalid data URL: missing data

Error message

Invalid data URL: missing data

What it means

parseDataUrl splits the data URL on the first comma to separate the metadata header from the payload. If no comma exists there is no data portion, so the string is a malformed data URL and this error is thrown.

Source

Thrown at frontend/util/util.ts:454

        if (code === 0x1b) return "\\x1b"; // escape
        if (code < 0x20 || code === 0x7f) return `\\x${code.toString(16).padStart(2, "0")}`;
        return ch;
    });
}

function cn(...inputs: ClassValue[]) {
    return twMerge(clsx(inputs));
}

type ParsedDataUrl = {
    mimeType: string;
    buffer: Uint8Array;
};

function parseDataUrl(dataUrl: string): ParsedDataUrl {
    if (!dataUrl.startsWith("data:")) throw new Error("Invalid data URL");
    const [header, data] = dataUrl.split(",", 2);
    if (data === undefined) throw new Error("Invalid data URL: missing data");

    const meta = header.slice(5);
    let mimeType = "text/plain;charset=US-ASCII";
    const parts = meta.split(";");
    if (parts[0]) mimeType = parts[0];
    const isBase64 = parts.some((p) => p.toLowerCase() === "base64");

    let buffer: Uint8Array;
    if (isBase64) {
        buffer = base64ToArray(data);
    } else {
        // assume text
        const decoded = decodeURIComponent(data);
        buffer = new TextEncoder().encode(decoded);
    }

    return { mimeType, buffer };
}

View on GitHub (pinned to a4447c1563)

Solutions

  1. Log/inspect dataUrl.length and content; confirm it contains a comma after the metadata header.
  2. Fix the producer to emit the full "data:<mime>[;base64],<payload>" form.
  3. If an empty payload is legitimate, encode it explicitly as "data:<mime>;base64," (with trailing comma) or guard before calling.
  4. Add a pre-check: `if (!dataUrl.includes(",")) handle-empty-case`.

Example fix

// before
const parsedUrl = parsed(`data:${mime}`); // no comma, no payload
// after
const parsedUrl = parsed(`data:${mime};base64,${btoa(payload)}`);
Defensive patterns

Strategy: validation

Validate before calling

function isWellFormedDataUrl(s: string): boolean {
  return s.startsWith("data:") && s.includes(",");
}
if (!isWellFormedDataUrl(dataUrl)) {
  throw new Error("data URL missing comma-separated payload: " + dataUrl.slice(0, 40));
}
const result = parsed(dataUrl);

Type guard

function isCompleteDataUrl(s: unknown): s is string {
  return typeof s === "string" && s.startsWith("data:") && s.includes(",");
}

Try / catch

try {
  return parsed(dataUrl);
} catch (e) {
  if (String(e.message).startsWith("Invalid data URL: missing data")) {
    console.error("truncated data URL, length:", dataUrl.length);
    return null;
  }
  throw e;
}

Prevention

When it happens

Trigger: Calling parseDataUrl with strings like "data:image/png" or "data:" — a scheme-correct but payload-less data URL with no ",<data>" part.

Common situations: Truncating the data URL (e.g. slicing for logging and passing the prefix back), building data URLs manually and forgetting the comma, or template interpolation of an empty base64 variable without the comma/separator.

Related errors


AI-assisted analysis of wavetermdev/waveterm@a4447c1563 (2026-09-01). Data as JSON: /api/errors/536049d9d4fa78e7. Report an issue: GitHub.