jgraph/drawio-desktop · error · Error
Invalid file data
Error message
Invalid file data
What it means
saveDraft (src/main/electron.js:3355-3362) refuses to persist a draft whose data fails checkFileContent — i.e. it does not begin with a recognised diagram signature (XML, mxfile/mxGraphModel/mxlibrary, JSON, PDF, PNG, JPG, SVG, VSDX, VSSX). Drafts are autosave artefacts, so refusing malformed content prevents corrupt drafts overwriting good ones.
Source
Thrown at src/main/electron.js:3361
let stat = await fsProm.lstat(draftsPaths[i]);
drafts.push({data: await fsProm.readFile(draftsPaths[i], 'utf8'),
created: stat.ctimeMs,
modified: stat.mtimeMs,
path: draftsPaths[i]});
}
catch (e){} // Ignore
}
return drafts;
};
async function saveDraft(fileObject, data)
{
var draftFileName = fileObject.draftFileName || getDraftFileName(fileObject);
if (!checkFileContent(data))
{
throw new Error('Invalid file data');
}
await assertWritablePath(draftFileName);
let draftFh;
try
{
draftFh = await fsProm.open(draftFileName, O_SYNC | O_CREAT | O_WRONLY | O_TRUNC);
await fsProm.writeFile(draftFh, data, 'utf8');
await draftFh.sync(); // Flush to disk
}
finally
{
await draftFh?.close();
}
if (isWin)View on GitHub (pinned to 403a2cb79f)
Solutions
- Confirm `data` is a non-empty diagram string starting with '<' (mxfile/mxGraphModel) or '['/'{' (JSON) before calling saveDraft.
- If you intentionally store base64, pass the matching encoding so checkFileContent decodes the header correctly.
- Suppress autosave when the editor buffer is empty or in an intermediate (non-serialised) state.
Example fix
// before saveDraft(fileObject, editor.getGraphXmlOrNull()); // after const xml = editor.getGraphXmlOrNull(); if (xml) saveDraft(fileObject, xml);
Defensive patterns
Strategy: validation
Validate before calling
function isValidDiagramString(data) {
return typeof data === 'string' && data.length > 0 &&
/^[<\[{]/.test(data[0]);
}
if (!isValidDiagramString(data)) throw new Error('nothing to draft'); Type guard
const isValidDiagramString = (d) => typeof d === 'string' && d.length > 0 && /^[<\[{]/.test(d[0]); Try / catch
try { await saveDraft(fileObject, data); }
catch (e) {
if (e.message === 'Invalid file data') { /* skip this autosave cycle, data not ready */ return; }
throw e;
} Prevention
- Skip autosave when the editor returns empty/null XML.
- Keep encoding consistent (utf8 for drafts) so the content gate passes.
- Do not pipe raw export bytes (PNG/PDF) into saveDraft.
When it happens
Trigger: Autosave fires with data that is null, empty, a fragment that does not start with a known magic byte/signature, or a string whose first 16 chars do not match any allowed header (e.g. plain text that is not XML/JSON, a base64 payload not in 'base64' encoding).
Common situations: Renderer passed an empty string during initial load; an exporter handed a non-diagram blob; encoding mismatch (data is base64 but enc was omitted so checkFileContent decoded it as raw text).
Related errors
AI-assisted analysis of jgraph/drawio-desktop@403a2cb79f (2026-08-13).
Data as JSON: /api/errors/02346d3993420b0c.
Report an issue: GitHub.