{"record":{"id":"db3d1e2abede98cc","repo":"chatboxai/chatbox","slug":"failed-to-create-temporary-export-file","errorCode":null,"errorMessage":"Failed to create temporary export file","messagePattern":"Failed to create temporary export file","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/renderer/platform/filter_writer.ts","lineNumber":552,"sourceCode":"        directory: Directory.Cache,\n        encoding: Encoding.UTF8,\n      })\n    }\n\n    try {\n      for await (const chunk of dataCallback()) {\n        bufferedContent += chunk\n        if (bufferedContent.length >= chunkSize) {\n          await flush()\n        }\n      }\n\n      if (bufferedContent || !tempUri) {\n        await flush()\n      }\n\n      if (!tempUri) {\n        throw new Error('Failed to create temporary export file')\n      }\n\n      log.warn('exportStreamingFileWithSystemPicker:tempWritten', {\n        filename,\n        path: tempPath,\n        uri: tempUri,\n        chunkCount,\n        totalLength,\n      })\n\n      const saveResult = await AndroidDocumentSaver.saveFile({\n        sourceUri: tempUri,\n        suggestedName: filename,\n        mimeType,\n      })\n      log.warn('exportStreamingFileWithSystemPicker:pickerSaved', saveResult)\n      await this.handlePostWrite({ uri: saveResult.uri })\n    } finally {","sourceCodeStart":534,"sourceCodeEnd":570,"githubUrl":"https://github.com/chatboxai/chatbox/blob/81571269addb6bafb589a920b2883f1e1e084fd1/src/renderer/platform/filter_writer.ts#L534-L570","documentation":"Thrown by exportStreamingFileWithSystemPicker after all streamed chunks have been flushed and the final guard still cannot find a temp file URI. The method relies on Capacitor's Filesystem.writeFile (Directory.Cache) to allocate tempUri on the first flush; if that call never produced a usable uri the export cannot be handed to AndroidDocumentSaver. This is the Android document-export fast path, so it only fires on Capacitor-backed Android builds.","triggerScenarios":"The async dataCallback yields content, flush() runs Filesystem.writeFile/appendFile into the Cache directory, but tempUri remains undefined after the terminal flush at line 547-549. Concretely: Filesystem.writeFile resolves without a .uri field, the Cache directory is unwritable (permissions, disk full / ENOSPC), or the Capacitor Filesystem plugin is not registered on the web layer so the call silently no-ops.","commonSituations":"Android device with restricted scoped-storage cache permissions, low-storage device where Cache writes fail, a misconfigured Capacitor build missing the Filesystem plugin, or an OS cleanup that invalidated the cache path mid-stream. Also seen when dataCallback() yields zero chunks and the empty-content writeFile returns no uri.","solutions":["Check the return of Filesystem.writeFile in flush() and throw/log when result.uri is missing instead of letting tempUri stay undefined.","Verify the Capacitor Filesystem plugin is installed and registered in capacitor.config and the Android MainActivity.","Ensure the app has cache write access and free space; surface a readable quota/permission error from Filesystem rather than the generic message.","Guard the empty-stream case explicitly: when dataCallback yields nothing, write a minimal placeholder before asserting tempUri."],"exampleFix":"// before\nconst result = await Filesystem.writeFile({ path: tempPath, data: content, directory: Directory.Cache, encoding: Encoding.UTF8, recursive: true })\ntempUri = result.uri\n// after\nconst result = await Filesystem.writeFile({ path: tempPath, data: content, directory: Directory.Cache, encoding: Encoding.UTF8, recursive: true })\nif (!result?.uri) throw new Error('Filesystem.writeFile returned no uri (cache unwritable or plugin missing)')\ntempUri = result.uri","handlingStrategy":"validation","validationCode":"// Before exporting, probe the Cache directory is writable\nimport { Filesystem, Directory } from '@capacitor/filesystem'\nasync function canWriteCache(): Promise<boolean> {\n  try {\n    const probe = await Filesystem.writeFile({ path: '__probe__', data: 'x', directory: Directory.Cache, recursive: true })\n    await Filesystem.deleteFile({ path: '__probe__', directory: Directory.Cache })\n    return Boolean(probe?.uri)\n  } catch {\n    return false\n  }\n}","typeGuard":"function hasUri(r: unknown): r is { uri: string } {\n  return typeof r === 'object' && r !== null && typeof (r as { uri?: unknown }).uri === 'string' && !!(r as { uri?: unknown }).uri\n}","tryCatchPattern":"try {\n  await exportStreamingFileWithSystemPicker(name, cb)\n} catch (err) {\n  if (err instanceof Error && err.message === 'Failed to create temporary export file') {\n    notifyUser('Export failed: cache directory is not writable. Free space or restart the app.')\n  } else throw err\n}","preventionTips":["Assert Filesystem.writeFile result.uri is non-empty before continuing the flush loop.","Verify the Capacitor Filesystem plugin is registered in the build before invoking export.","Surface a storage-permission/quota error from Filesystem instead of a generic message."],"tags":["android","capacitor","filesystem","export","storage"],"backgroundTag":null,"analyzedSha":"81571269addb6bafb589a920b2883f1e1e084fd1","analyzedAt":"2026-08-12T21:51:44.981Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}