{"record":{"id":"02720fb8e63ec451","repo":"stablyai/orca","slug":"destination-folder-already-exists","errorCode":null,"errorMessage":"Destination folder already exists","messagePattern":"Destination folder already exists","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"warning","filePath":"src/main/ipc/filesystem-download-folder.ts","lineNumber":35,"sourceCode":"  return value\n}\n\nfunction createSiblingTransferPath(destinationPath: string, suffix: string): string {\n  // Why: promotion uses rename/no-clobber operations that must stay on the\n  // destination volume, so transfer paths intentionally remain siblings.\n  return join(dirname(destinationPath), `.${randomUUID()}.${suffix}`)\n}\n\nasync function assertDownloadFolderDestinationAvailable(destinationPath: string): Promise<void> {\n  try {\n    await stat(destinationPath)\n  } catch (error) {\n    if (isENOENT(error)) {\n      return\n    }\n    throw error\n  }\n  throw new Error('Destination folder already exists')\n}\n\nasync function cleanupLocalTransferDirectory(dirPath: string): Promise<void> {\n  try {\n    await rm(dirPath, { recursive: true, force: true })\n  } catch (error) {\n    // Why: cleanup must not mask the transfer error, but a leaked recursive\n    // download tree needs enough visibility to diagnose and remove it.\n    console.warn(`[filesystem] Failed to remove temporary folder download '${dirPath}'`, error)\n  }\n}\n\n// Why: keep folder-download IPC out of filesystem.ts — that module is already large.\nexport function registerFilesystemDownloadFolderHandlers(): void {\n  ipcMain.handle(\n    'fs:downloadFolder',\n    async (\n      event,","sourceCodeStart":17,"sourceCodeEnd":53,"githubUrl":"https://github.com/stablyai/orca/blob/1136503c6a231a16dce8f921f6fadb63d181e8db/src/main/ipc/filesystem-download-folder.ts#L17-L53","documentation":"Thrown by assertDownloadFolderDestinationAvailable() after the user picks a destination parent folder in the OS dialog. The handler joins destinationParent with the sanitized remote basename and stat()s the resulting path; if stat succeeds the name is already taken, so the download is aborted before any transfer. ENOENT is the only acceptable result (path is free); any other stat error is re-thrown. This is a deliberate pre-flight collision check so the later rename-based promotion does not clobber existing data.","triggerScenarios":"fs:downloadFolder is invoked, the user selects e.g. ~/Downloads, and a folder or file named like the remote directory (after sanitizeLocalDownloadFileName) already exists directly under that chosen parent. Also reachable if a previous download of the same remote folder left a same-named directory behind.","commonSituations":"Repeated downloads of the same remote folder into the same parent; a file and folder name clash; a sanitized basename that collided after illegal characters were stripped; a leftover partial download from a crashed prior run that was not cleaned up.","solutions":["Choose a different destination parent folder in the dialog.","Rename or move the existing same-named entry out of the chosen parent before retrying.","If the existing entry is a stale partial download, delete it and retry.","Sanitize/seed a different destination basename upstream if collisions are routine."],"exampleFix":"// before: destination = ~/Downloads/myproj (already exists)\n// after: pick an empty parent, or rename existing first\nawait fs.rename(`${destParent}/${basename}`, `${destParent}/${basename}.old`)\n// then retry fs:downloadFolder","handlingStrategy":"validation","validationCode":"// After the user picks a destination parent, pre-check the joined path is free\nimport { stat } from 'node:fs/promises'\nimport { join } from 'node:path'\nasync function isDestFree(parent: string, basename: string): Promise<boolean> {\n  try { await stat(join(parent, basename)); return false } catch { return true }\n}","typeGuard":null,"tryCatchPattern":"// Treat the IPC error as a recoverable name collision\ntry {\n  await window.api.fs.downloadFolder({ dirPath, connectionId })\n} catch (e) {\n  if (e instanceof Error && /already exists/.test(e.message)) {\n    // prompt user to pick another parent or rename, then retry\n  } else throw e\n}","preventionTips":["Before invoking download, check whether destinationParent/<basename> already exists and prompt to overwrite/rename.","Clean up leftover partial downloads from prior failed runs.","Keep the sanitized basename stable so collisions are predictable."],"tags":["filesystem","name-collision","download","ssh"],"backgroundTag":null,"analyzedSha":"1136503c6a231a16dce8f921f6fadb63d181e8db","analyzedAt":"2026-08-12T23:15:58.167Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}