NousResearch/hermes-agent · warning · Error
Invalid PDF data URL type
Error message
Invalid PDF data URL type
What it means
Second guard in dataUrlToBlob: the metadata segment between 'data:' and the comma must declare media type 'application/pdf' and include a 'base64' parameter (case-insensitive after trimming). This error means the data URL is structurally valid but is not a base64-encoded PDF — e.g. an image/png data URL, a text/plain payload, or a PDF encoded without the base64 marker.
Source
Thrown at apps/desktop/src/app/chat/right-rail/preview-file.tsx:237
return suspicious / Math.min(bytes.length, 4096) > 0.12
}
function dataUrlToBlob(dataUrl: string) {
const comma = dataUrl.indexOf(',')
if (comma < 0 || !dataUrl.startsWith('data:')) {
throw new Error('Invalid PDF data URL')
}
const metadata = dataUrl
.slice(5, comma)
.split(';')
.map(part => part.trim().toLowerCase())
const payload = dataUrl.slice(comma + 1)
if (metadata[0] !== 'application/pdf' || !metadata.slice(1).includes('base64')) {
throw new Error('Invalid PDF data URL type')
}
let binary: string
try {
binary = atob(decodeURIComponent(payload))
} catch {
throw new Error('Invalid PDF data URL payload')
}
if (!binary.startsWith('%PDF-')) {
throw new Error('Invalid PDF file header')
}
const bytes = new Uint8Array(binary.length)
for (let index = 0; index < binary.length; index += 1) {
bytes[index] = binary.charCodeAt(index)View on GitHub (pinned to c896c09c42)
Solutions
- Detect the MIME from the data URL itself and dispatch to the matching preview (image viewer for image/*, text for text/*) instead of assuming PDF.
- Fix the payload producer to emit `data:application/pdf;base64,...` exactly.
- If the PDF arrives without base64 (raw percent-encoded), add an encoding branch instead of loosening this check.
- Validate attachment metadata against the actual data URL header before opening the preview.
Example fix
// before
if (metadata[0] !== 'application/pdf' || !metadata.slice(1).includes('base64')) {
throw new Error('Invalid PDF data URL type')
}
// after — accept the alias some producers emit, keep the contract strict
const mime = metadata[0] === 'pdf' ? 'application/pdf' : metadata[0]
if (mime !== 'application/pdf' || !metadata.slice(1).includes('base64')) {
throw new Error('Invalid PDF data URL type')
} Defensive patterns
Strategy: type-guard
Validate before calling
const mime = dataUrl.slice(5, dataUrl.indexOf(','))
const kind = mime.split(';')[0]
switch (kind) {
case 'application/pdf': openPdfPreview(dataUrl); break
case 'image/png': case 'image/jpeg': openImagePreview(dataUrl); break
default: openTextPreview(dataUrl)
} Type guard
const isPdfDataUrl = (s: string): boolean => /^data:application\/pdf;base64,/i.test(s)
Try / catch
try { blob = dataUrlToBlob(url) } catch (e) { /* check message === 'Invalid PDF data URL type' -> route by MIME to another previewer */ } Prevention
- Derive preview type from the data URL MIME segment, not the filename
- Fix producers to emit exactly data:application/pdf;base64,
- Test with image/* and text/* data URLs to prove dispatch works
When it happens
Trigger: Passing a data URL whose MIME is image/*, text/*, or application/octet-stream into the PDF preview; a producer that emitted 'data:pdf;base64' (non-standard type) or omitted ';base64' and inlined raw bytes.
Common situations: Attachment kind detection guessing 'pdf' from a .pdf-ish filename while the actual payload is a PNG screenshot; generic preview code funnelling every data URL through the PDF converter; upstream models/tools emitting non-standard MIME tokens.
Related errors
- Invalid PDF data URL
- Invalid PDF data URL payload
- Invalid PDF file header
- Invalid data URL
- Invalid preview URL
AI-assisted analysis of NousResearch/hermes-agent@c896c09c42 (2026-08-14).
Data as JSON: /api/errors/1c411ca91bf239ad.
Report an issue: GitHub.