jgraph/drawio-desktop · error · Error
bad arg: fileObject
Error message
bad arg: fileObject
What it means
In the rendererReq switch (src/main/electron.js:3840-3844), the 'saveFile' case throws 'bad arg: fileObject' when args.fileObject is null/undefined before reqStr validates fileObject.path. This is the IPC entry guard for saveFile.
Source
Thrown at src/main/electron.js:3841
fonts = [...new Set(fonts)].sort(
(a, b) => a.localeCompare(b));
resolve(fonts);
});
});
}
ipcMain.on("rendererReq", async (event, args) =>
{
if (!validateSender(event.senderFrame)) return null;
try
{
let ret = null;
switch(args.action)
{
case 'saveFile':
if (args.fileObject == null) throw new Error('bad arg: fileObject');
reqStr(args.fileObject.path, 'fileObject.path');
ret = await saveFile(args.fileObject, args.data, args.origStat, args.overwrite, args.defEnc);
break;
case 'writeFile':
reqStr(args.path, 'path');
ret = await writeFile(args.path, args.data, args.enc);
break;
case 'saveDraft':
if (args.fileObject == null) throw new Error('bad arg: fileObject');
reqStr(args.fileObject.path, 'fileObject.path');
ret = await saveDraft(args.fileObject, args.data);
break;
case 'getFileDrafts':
if (args.fileObject == null) throw new Error('bad arg: fileObject');
reqStr(args.fileObject.path, 'fileObject.path');
ret = await getFileDrafts(args.fileObject);
break;
case 'getBkpFile':View on GitHub (pinned to 403a2cb79f)
Solutions
- Ensure the renderer constructs a fileObject ({path, encoding?}) before dispatching saveFile.
- Gate the save button/menu on fileObject presence.
- Log args at dispatch to confirm fileObject was set.
Example fix
// before
if (xml) electron.request({action: 'saveFile', fileObject: currentFile, data: xml});
// after
if (xml && currentFile && currentFile.path) {
electron.request({action: 'saveFile', fileObject: currentFile, data: xml});
} Defensive patterns
Strategy: type-guard
Validate before calling
const hasFileObject = (args) => args && args.fileObject != null && typeof args.fileObject === 'object';
if (!hasFileObject(args)) throw new TypeError('fileObject required'); Type guard
function hasFileObject(args) {
return args != null && args.fileObject != null && typeof args.fileObject === 'object';
} Try / catch
try { await electron.request({action: 'saveFile', fileObject, data}); }
catch (e) {
if (e.message === 'bad arg: fileObject') { /* prompt user to Save As first */ return; }
throw e;
} Prevention
- Disable Save until a fileObject exists (after open or Save As).
- Centralise fileObject construction in one renderer module.
- Log the IPC payload shape when this fires to catch regressions.
When it happens
Trigger: Renderer sends {action: 'saveFile', fileObject: null, data} or omits fileObject entirely.
Common situations: Save triggered before a file was opened/created (no fileObject yet); a refactor dropped the fileObject from the payload; structured-clone dropped a non-cloneable fileObject.
Related errors
- bad arg: ${name}
- bad arg: fileObject.path
- path not authorised
- Invalid file data
- all saving trials failed
AI-assisted analysis of jgraph/drawio-desktop@403a2cb79f (2026-08-13).
Data as JSON: /api/errors/662ad26dae7712c9.
Report an issue: GitHub.