NousResearch/hermes-agent · error · Error

Invalid data URL

Error message

Invalid data URL

What it means

Thrown when rawUrl starts with 'data:' but does not match /^data:([^;,]+)?(;base64)?,(.*)$/s — i.e. there is no comma separating metadata from payload, or the URL is malformed in a way the regex rejects. Only the segment before the first comma and an optional ';base64' flag are tolerated; anything else (e.g. url-encoded commas removed, truncated paste) fails.

Source

Thrown at apps/desktop/electron/main.ts:4681

      return clean
    })

  titleInflight.set(key, pending)

  return pending
}

async function resourceBufferFromUrl(rawUrl) {
  if (!rawUrl) {
    throw new Error('Missing URL')
  }

  if (rawUrl.startsWith('data:')) {
    const match = rawUrl.match(/^data:([^;,]+)?(;base64)?,(.*)$/s)

    if (!match) {
      throw new Error('Invalid data URL')
    }

    const mimeType = match[1] || 'application/octet-stream'
    const encoded = match[3] || ''
    const buffer = match[2] ? Buffer.from(encoded, 'base64') : Buffer.from(decodeURIComponent(encoded), 'utf8')

    return { buffer, mimeType }
  }

  if (/^file:/i.test(rawUrl)) {
    const { resolvedPath } = await resolveReadableFileForIpc(rawUrl, { purpose: 'Image file' })
    const buffer = await fs.promises.readFile(resolvedPath)

    return { buffer, mimeType: mimeTypeForPath(resolvedPath) }
  }

  const parsed = new URL(rawUrl)
  const client = parsed.protocol === 'https:' ? https : http

View on GitHub (pinned to c896c09c42)

Solutions

  1. Verify the data URL has the form data:<mime>[;base64],<payload> with a comma and non-empty payload.
  2. Log the first ~80 chars of the failing URL to spot truncation or mangling.
  3. Regenerate the data URL at the source rather than string-editing it.

Example fix

// before
const buf = await resourceBufferFromUrl(someSrc)

// after — pre-validate the data URL shape before the IPC call
function isPlausibleDataUrl(u) {
  return /^data:[^;,]*(;base64)?,.+/s.test(u || '')
}
if (!isPlausibleDataUrl(someSrc)) throw new Error('Invalid data URL')
const buf = await resourceBufferFromUrl(someSrc)
Defensive patterns

Strategy: validation

Validate before calling

const DATA_URL_RE = /^data:[^;,]*(;base64)?,.+$/s
function isPlausibleDataUrl(u) {
  return typeof u === 'string' && DATA_URL_RE.test(u)
}

Type guard

function isDataUrl(u) {
  return typeof u === 'string' && u.startsWith('data:') && u.includes(',')
}

Try / catch

try {
  const { buffer } = await resourceBufferFromUrl(url)
} catch (e) {
  if (e.message === 'Invalid data URL') logTruncated(url)
  else throw e
}

Prevention

When it happens

Trigger: A truncated data URL (clipboard paste lost the tail after the comma); a data URL using non-standard parameters before the comma beyond mime[;base64]; a string like 'data:' with no payload at all.

Common situations: Copying images from web apps that build data URLs dynamically and occasionally emit 'data:image/png;base64,' with empty payload; string manipulation upstream that strips or mangles commas.

Related errors


AI-assisted analysis of NousResearch/hermes-agent@c896c09c42 (2026-08-14). Data as JSON: /api/errors/03be665f88914b9e. Report an issue: GitHub.