{"record":{"id":"02346d3993420b0c","repo":"jgraph/drawio-desktop","slug":"invalid-file-data","errorCode":null,"errorMessage":"Invalid file data","messagePattern":"Invalid file data","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/main/electron.js","lineNumber":3361,"sourceCode":"\t\t\tlet stat = await fsProm.lstat(draftsPaths[i]);\n\t\t\tdrafts.push({data: await fsProm.readFile(draftsPaths[i], 'utf8'), \n\t\t\t\t\t\tcreated: stat.ctimeMs,\n\t\t\t\t\t\tmodified: stat.mtimeMs,\n\t\t\t\t\t\tpath: draftsPaths[i]});\n\t\t}\n\t\tcatch (e){} // Ignore\n\t}\n\n\treturn drafts;\n};\n\nasync function saveDraft(fileObject, data)\n{\n\tvar draftFileName = fileObject.draftFileName || getDraftFileName(fileObject);\n\n\tif (!checkFileContent(data))\n\t{\n\t\tthrow new Error('Invalid file data');\n\t}\n\n\tawait assertWritablePath(draftFileName);\n\n\tlet draftFh;\n\n\ttry\n\t{\n\t\tdraftFh = await fsProm.open(draftFileName, O_SYNC | O_CREAT | O_WRONLY | O_TRUNC);\n\t\tawait fsProm.writeFile(draftFh, data, 'utf8');\n\t\tawait draftFh.sync(); // Flush to disk\n\t}\n\tfinally\n\t{\n\t\tawait draftFh?.close();\n\t}\n\n\tif (isWin)","sourceCodeStart":3343,"sourceCodeEnd":3379,"githubUrl":"https://github.com/jgraph/drawio-desktop/blob/403a2cb79f431db13a395f033b67eeebc1631754/src/main/electron.js#L3343-L3379","documentation":"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.","triggerScenarios":"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).","commonSituations":"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).","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."],"exampleFix":"// before\nsaveDraft(fileObject, editor.getGraphXmlOrNull());\n\n// after\nconst xml = editor.getGraphXmlOrNull();\nif (xml) saveDraft(fileObject, xml);","handlingStrategy":"validation","validationCode":"function isValidDiagramString(data) {\n\treturn typeof data === 'string' && data.length > 0 &&\n\t\t/^[<\\[{]/.test(data[0]);\n}\nif (!isValidDiagramString(data)) throw new Error('nothing to draft');","typeGuard":"const isValidDiagramString = (d) => typeof d === 'string' && d.length > 0 && /^[<\\[{]/.test(d[0]);","tryCatchPattern":"try { await saveDraft(fileObject, data); }\ncatch (e) {\n\tif (e.message === 'Invalid file data') { /* skip this autosave cycle, data not ready */ return; }\n\tthrow e;\n}","preventionTips":["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."],"tags":["autosave","validation","draft","file-content"],"backgroundTag":null,"analyzedSha":"403a2cb79f431db13a395f033b67eeebc1631754","analyzedAt":"2026-08-13T00:15:02.468Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}