{"record":{"id":"72debc9c0bf7ff3e","repo":"jgraph/drawio-desktop","slug":"all-saving-trials-failed","errorCode":null,"errorMessage":"all saving trials failed","messagePattern":"all saving trials failed","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/main/electron.js","lineNumber":3478,"sourceCode":"\t\t\tawait fh?.close();\n\t\t}\n\n\t\tlet stat2 = await fsProm.stat(fileObject.path);\n\t\t// Workaround for possible writing errors is to check the written\n\t\t// contents of the file and retry 3 times before showing an error\n\t\tlet writtenData = await fsProm.readFile(fileObject.path, writeEnc);\n\t\t\n\t\tif (data != writtenData)\n\t\t{\n\t\t\tretryCount++;\n\t\t\t\n\t\t\tif (retryCount < 3)\n\t\t\t{\n\t\t\t\treturn await writeFile();\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tthrow new Error('all saving trials failed');\n\t\t\t}\n\t\t}\n\t\telse\n\t\t{\n\t\t\t//We'll keep the backup file in case the original file is corrupted. TODO When should we delete the backup file?\n\t\t\tif (backupCreated)\n\t\t\t{\n\t\t\t\t//fs.unlink(bkpPath, (err) => {}); //Ignore errors!\n\n\t\t\t\t//Delete old backup file with old prefix\n\t\t\t\tif (fs.existsSync(oldBkpPath))\n\t\t\t\t{\n\t\t\t\t\ttry\n\t\t\t\t\t{\n\t\t\t\t\t\tawait assertWritablePath(oldBkpPath);\n\t\t\t\t\t\tfs.unlink(oldBkpPath, (err) => {}); //Ignore errors\n\t\t\t\t\t}\n\t\t\t\t\tcatch (e) {} //Ignore — path failed authorisation, skip cleanup.","sourceCodeStart":3460,"sourceCodeEnd":3496,"githubUrl":"https://github.com/jgraph/drawio-desktop/blob/403a2cb79f431db13a395f033b67eeebc1631754/src/main/electron.js#L3460-L3496","documentation":"saveFile's writeFile inner function verifies the written file by reading it back and comparing to the intended data (src/main/electron.js:3466-3480); after 3 unsuccessful retries it throws 'all saving trials failed'. Each retry rewrites the file with O_SYNC, so persistent mismatch points to fs-level corruption, encoding round-trip loss, or external mutation.","triggerScenarios":"Disk full, quota exceeded, a synchronisation client (OneDrive/Dropbox/Cryptomator) racing the write, an antivirus intercepting the write, or an encoding (e.g. base64) whose write-then-read round-trip is not identity.","commonSituations":"Cloud-sync folders that hold a write lock or stage partial content; an AV scanner quarantining the file; misconfigured writeEnc so writeFile writes one encoding but reads back with another; failing disk sectors.","solutions":["Save to a local, non-synced directory to rule out cloud-sync interference.","Verify writeEnc is consistent: saveFile reads back with the same `writeEnc = defEnc || fileObject.encoding` it wrote with — if encoding metadata drifts between writes the round-trip will never match.","Check disk space and that the target volume supports O_SYNC.","Temporarily disable AV/EDR to confirm it is intercepting the write."],"exampleFix":"// before\nawait saveFile(fileObject, data, origStat, false, 'utf8');\n// (writeEnc drifts because fileObject.encoding is base64 on a later call)\n\n// after\nfileObject.encoding = 'utf8';\nawait saveFile(fileObject, data, origStat, false, 'utf8');","handlingStrategy":"retry","validationCode":"async function diskCanRoundTrip(p, data, enc) {\n\tawait fsPromises.writeFile(p, data, enc);\n\tconst back = await fsPromises.readFile(p, enc);\n\treturn back === data;\n}","typeGuard":null,"tryCatchPattern":"try { await saveFile(fileObject, data, stat, false); }\ncatch (e) {\n\tif (e.message === 'all saving trials failed') {\n\t\t/* prompt to retry, or save to a different (local) location */\n\t} else throw e;\n}","preventionTips":["Avoid saving directly into cloud-sync folders; pause sync or use a local staging dir.","Keep writeEnc consistent across the save lifecycle (defEnc || fileObject.encoding).","Free disk space and disable AV intercepts when triaging this error.","For binary/base64, confirm the encoding round-trips identically."],"tags":["save","filesystem","retry","cloud-sync","integrity"],"backgroundTag":null,"analyzedSha":"403a2cb79f431db13a395f033b67eeebc1631754","analyzedAt":"2026-08-13T00:15:02.468Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}