{"record":{"id":"76ae69927f042068","repo":"OtterMind/Chat2DB","slug":"failed-to-update-local-file","errorCode":null,"errorMessage":"Failed to update local file","messagePattern":"Failed to update local file","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"chat2db-community-client/src/utils/file.ts","lineNumber":85,"sourceCode":"  const filePath = await sqlService.downloadLargeCellValue({ largeValueId, format });\n  if (filePath) {\n    jcefApi?.revealInExplorer(filePath);\n  }\n}\n\n// Update file content\nexport function updateFileContent({\n  filePath,\n  fileContent,\n  charset,\n  bom,\n}: {\n  filePath: string;\n  fileContent: string;\n} & LocalFileEncodingMetadata) {\n  return jcefApi.updateFileContent({ filePath, fileContent, charset, bom }).then((updated) => {\n    if (updated !== true) {\n      throw new Error('Failed to update local file');\n    }\n    return updated;\n  });\n}\n\ninterface SavedDesktopFile {\n  path: string;\n  size: number;\n}\n\n// save file\nexport function saveFileToDesktop({\n  fileName,\n  fileContent,\n  fileType,\n}: {\n  fileName: string;\n  fileContent: string;","sourceCodeStart":67,"sourceCodeEnd":103,"githubUrl":"https://github.com/OtterMind/Chat2DB/blob/5ee1e990e73fbcae1969dc554be254fedb3ab888/chat2db-community-client/src/utils/file.ts#L67-L103","documentation":"updateFileContent throws 'Failed to update local file' when jcefApi.updateFileContent returns a value that is not strictly true. This is a desktop-only (JCEF bridge) function that writes content to a local file on disk via the Java host. The boolean return indicates success; anything else (false, undefined, null) means the write failed — e.g., the file is read-only, the path doesn't exist, permission denied, or the JCEF handler rejected the write.","triggerScenarios":"Calling updateFileContent({ filePath, fileContent, charset, bom }) where: (1) the file is read-only or permission-denied, (2) the filePath doesn't exist or is invalid, (3) the JCEF host-side handler encounters an I/O error, (4) charset/bom parameters are incompatible with the file.","commonSituations":"File on disk is locked by another process. Directory was deleted. Desktop app runs without write permission (e.g., system directory). filePath from a stale state pointing to a moved/deleted file.","solutions":["Verify filePath exists and is writable before calling updateFileContent.","Wrap in try/catch and surface the error to the user with a retry option.","Check if the file is locked by another application.","Ensure the JCEF bridge (jcefApi.updateFileContent) is connected and the host handler is functional."],"exampleFix":"// before\nawait updateFileContent({ filePath, fileContent, charset, bom });\n\n// after\ntry {\n  await updateFileContent({ filePath, fileContent, charset, bom });\n} catch (e) {\n  if (e instanceof Error && /Failed to update local file/.test(e.message)) {\n    message.error('Cannot save file. Check it is not locked or read-only.');\n    return;\n  }\n  throw e;\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  await updateFileContent({ filePath, fileContent, charset, bom });\n} catch (e) {\n  if (e instanceof Error && /Failed to update local file/.test(e.message)) {\n    message.error('Cannot save the file. Verify it exists and is writable.');\n    return false;\n  }\n  throw e;\n}","preventionTips":["Check file existence and writability before calling updateFileContent.","Inform the user to close the file in other editors before saving.","Ensure the JCEF host handler for updateFileContent is connected and functional."],"tags":["desktop","jcef","file-handling","io","frontend"],"backgroundTag":null,"analyzedSha":"5ee1e990e73fbcae1969dc554be254fedb3ab888","analyzedAt":"2026-08-14T07:05:03.077Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}