iOfficeAI/AionUi · error · Error

File data not found

Error message

File data not found

What it means

Thrown by downloadFileFromPath when the IPC call ipcBridge.fs.getImageBase64.invoke returns a falsy value (empty string or null) for the given file path. This means the main process read the file but produced no base64 data, or the file simply does not exist at the path provided. It is a renderer-side guard before attempting a blob download.

Source

Thrown at packages/desktop/src/renderer/utils/file/download.ts:30

function triggerBlobDownload(blob: Blob, file_name: string): void {
  const url = URL.createObjectURL(blob);
  const link = document.createElement('a');
  link.href = url;
  link.download = file_name;
  document.body.appendChild(link);
  link.click();
  document.body.removeChild(link);
  URL.revokeObjectURL(url);
}

/**
 * Download a file by reading its raw bytes from disk (works in both Electron and WebUI).
 * Uses getImageBase64 + in-memory atob decode to bypass CSP connect-src restrictions.
 */
export async function downloadFileFromPath(file_path: string, file_name: string, workspace?: string): Promise<void> {
  const dataUrl = await ipcBridge.fs.getImageBase64.invoke({ path: file_path, workspace });
  if (!dataUrl) {
    throw new Error('File data not found');
  }
  const ext = file_name.split('.').pop()?.toLowerCase() ?? '';
  const mimeType = BINARY_MIME_MAP[ext] ?? 'application/octet-stream';
  const blob = base64ToBlob(dataUrl, mimeType);
  triggerBlobDownload(blob, file_name);
}

/**
 * Download a file addressed by its renderer-safe file reference.
 *
 * Fetch the backend's raw byte stream rather than carrying the complete file as
 * base64 inside JSON. This is the same endpoint used by PDF previews and works
 * through both Electron's local backend and WebUI's same-origin reverse proxy.
 */
export async function downloadFileFromRef(file: ChatFileRef, file_name: string): Promise<void> {
  const response = await fetch(buildFileStreamUrl(file));
  if (!response.ok) throw new Error(`File download failed (${response.status})`);
  const blob = await response.blob();

View on GitHub (pinned to 711aa0550e)

Solutions

  1. Verify the file exists on disk at the exact path before calling download (fs stat via IPC or the main process).
  2. Confirm you are passing the correct workspace argument matching where the file was created.
  3. If the file was generated by a tool, re-run the tool or regenerate the artifact, then retry the download.
  4. Add a user-facing message when getImageBase64 returns empty instead of a raw throw.

Example fix

// before
await downloadFileFromPath(path, name);

// after
const dataUrl = await ipcBridge.fs.getImageBase64.invoke({ path, workspace });
if (!dataUrl) {
  message.error(t('download.fileMissing', { defaultValue: 'File no longer exists' }));
  return;
}
await downloadFileFromPath(path, name, workspace);
Defensive patterns

Strategy: validation

Validate before calling

const exists = await ipcBridge.fs.getFileStats?.invoke({ path: file_path, workspace });
if (!exists) {
  // show 'file missing' UI instead of calling downloadFileFromPath
}

Type guard

const hasFileData = (d: string | null | undefined): d is string =>
  typeof d === 'string' && d.length > 0;

Try / catch

try { await downloadFileFromPath(p, n, ws); } catch (e) { if ((e as Error).message === 'File data not found') { /* notify user, offer regenerate */ } else { throw e; } }

Prevention

When it happens

Trigger: Calling downloadFileFromPath with a file_path that has been deleted or moved (e.g. a chat artifact cleaned up from disk), passing a relative path when the IPC expects an absolute one, or supplying a workspace that does not contain the file so the main-process lookup resolves to nothing.

Common situations: Downloading generated images/files after the workspace cache or temp directory was cleared, stale chat history referencing removed artifacts, path mismatches between Windows and Unix separators, or the file existing in a different workspace than the one passed.

Understand the failure class

Background: "File not found" and ENOENT errors: why libraries can't find a file that should exist — this error's family across 50 libraries.

Related errors


AI-assisted analysis of iOfficeAI/AionUi@711aa0550e (2026-08-28). Data as JSON: /api/errors/65bda5853ec2928d. Report an issue: GitHub.