{"record":{"id":"03be665f88914b9e","repo":"NousResearch/hermes-agent","slug":"invalid-data-url","errorCode":null,"errorMessage":"Invalid data URL","messagePattern":"Invalid data URL","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"apps/desktop/electron/main.ts","lineNumber":4681,"sourceCode":"\n      return clean\n    })\n\n  titleInflight.set(key, pending)\n\n  return pending\n}\n\nasync function resourceBufferFromUrl(rawUrl) {\n  if (!rawUrl) {\n    throw new Error('Missing URL')\n  }\n\n  if (rawUrl.startsWith('data:')) {\n    const match = rawUrl.match(/^data:([^;,]+)?(;base64)?,(.*)$/s)\n\n    if (!match) {\n      throw new Error('Invalid data URL')\n    }\n\n    const mimeType = match[1] || 'application/octet-stream'\n    const encoded = match[3] || ''\n    const buffer = match[2] ? Buffer.from(encoded, 'base64') : Buffer.from(decodeURIComponent(encoded), 'utf8')\n\n    return { buffer, mimeType }\n  }\n\n  if (/^file:/i.test(rawUrl)) {\n    const { resolvedPath } = await resolveReadableFileForIpc(rawUrl, { purpose: 'Image file' })\n    const buffer = await fs.promises.readFile(resolvedPath)\n\n    return { buffer, mimeType: mimeTypeForPath(resolvedPath) }\n  }\n\n  const parsed = new URL(rawUrl)\n  const client = parsed.protocol === 'https:' ? https : http","sourceCodeStart":4663,"sourceCodeEnd":4699,"githubUrl":"https://github.com/NousResearch/hermes-agent/blob/c896c09c42910c584c4c7d2325b58c14713ea42c/apps/desktop/electron/main.ts#L4663-L4699","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Verify the data URL has the form data:<mime>[;base64],<payload> with a comma and non-empty payload.","Log the first ~80 chars of the failing URL to spot truncation or mangling.","Regenerate the data URL at the source rather than string-editing it."],"exampleFix":"// before\nconst buf = await resourceBufferFromUrl(someSrc)\n\n// after — pre-validate the data URL shape before the IPC call\nfunction isPlausibleDataUrl(u) {\n  return /^data:[^;,]*(;base64)?,.+/s.test(u || '')\n}\nif (!isPlausibleDataUrl(someSrc)) throw new Error('Invalid data URL')\nconst buf = await resourceBufferFromUrl(someSrc)","handlingStrategy":"validation","validationCode":"const DATA_URL_RE = /^data:[^;,]*(;base64)?,.+$/s\nfunction isPlausibleDataUrl(u) {\n  return typeof u === 'string' && DATA_URL_RE.test(u)\n}","typeGuard":"function isDataUrl(u) {\n  return typeof u === 'string' && u.startsWith('data:') && u.includes(',')\n}","tryCatchPattern":"try {\n  const { buffer } = await resourceBufferFromUrl(url)\n} catch (e) {\n  if (e.message === 'Invalid data URL') logTruncated(url)\n  else throw e\n}","preventionTips":["Don't hand-edit data URL strings","Validate shape before sending over IPC","Watch for clipboard truncation of long data URLs"],"tags":["url","data-url","validation","image","desktop"],"backgroundTag":null,"analyzedSha":"c896c09c42910c584c4c7d2325b58c14713ea42c","analyzedAt":"2026-08-14T17:18:01.089Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}