{"record":{"id":"b5e5bd8b32435406","repo":"stablyai/orca","slug":"a-file-or-folder-named-basename-targetpath-a","errorCode":null,"errorMessage":"A file or folder named '${basename(targetPath)}' already exists in this location","messagePattern":"A file or folder named '(.+?)' already exists in this location","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"warning","filePath":"src/main/ipc/filesystem-mutations.ts","lineNumber":57,"sourceCode":"    if (code === 'EACCES' || code === 'EPERM') {\n      throw new Error(`Permission denied: unable to create '${name}'`)\n    }\n  }\n  throw error\n}\n\n/**\n * Ensure `targetPath` does not already exist. Throws if it does.\n *\n * Note: this is a non-atomic check — a concurrent operation could create the\n * path between `lstat` and the caller's next action. Acceptable for a desktop\n * app with low concurrency; `createFile` uses the `wx` flag for an atomic\n * alternative where possible.\n */\nasync function assertNotExists(targetPath: string): Promise<void> {\n  try {\n    await lstat(targetPath)\n    throw new Error(\n      `A file or folder named '${basename(targetPath)}' already exists in this location`\n    )\n  } catch (error) {\n    if (!isENOENT(error)) {\n      throw error\n    }\n  }\n}\n\n/**\n * IPC handlers for file/folder creation and renaming.\n * Deletion is handled separately via `fs:deletePath` (shell.trashItem).\n */\nexport function registerFilesystemMutationHandlers(store: Store): void {\n  ipcMain.handle(\n    'fs:createFile',\n    async (\n      _event,","sourceCodeStart":39,"sourceCodeEnd":75,"githubUrl":"https://github.com/stablyai/orca/blob/1136503c6a231a16dce8f921f6fadb63d181e8db/src/main/ipc/filesystem-mutations.ts#L39-L75","documentation":"Thrown by assertNotExists() in the local 'fs:createDir' handler. It lstat()s the target dirPath; if lstat succeeds the path exists and the create is rejected with a friendly collision message naming basename(targetPath). Only ENOENT is allowed through (path free). This is an explicit, non-atomic pre-check (documented as such) that gives a clear message before mkdir is attempted.","triggerScenarios":"fs:createDir is invoked locally for a dirPath that already exists as a file or directory; lstat resolves the path, so both a same-named file and a same-named folder trigger it.","commonSituations":"User creates a folder with a name already used in that location; a same-named file blocks the folder creation; a duplicate 'New Folder' action.","solutions":["Choose a different folder name.","Delete or rename the existing file/folder with that name if a folder is genuinely wanted there.","Deconflict the name in the renderer before issuing fs:createDir."],"exampleFix":"// before: await fs.createDir(`${dir}/${name}`) where name exists\n// after: pick a unique folder name, or remove the blocker first\nawait fs.createDir(`${dir}/${name}-folder`)","handlingStrategy":"validation","validationCode":"// Pre-check before createDir\nimport { lstat } from 'node:fs/promises'\nasync function dirTargetIsFree(p: string): Promise<boolean> {\n  try { await lstat(p); return false } catch { return true }\n}","typeGuard":null,"tryCatchPattern":"try {\n  await window.api.fs.createDir({ dirPath })\n} catch (e) {\n  if (e instanceof Error && /already exists/.test(e.message)) {\n    // prompt for a unique folder name and retry\n  } else throw e\n}","preventionTips":["Deconflict folder names in the UI before issuing createDir.","Remove a same-named file/folder blocker first if a folder is genuinely wanted there.","Remember createDir intentionally rejects existing names — do not auto-retry unchanged."],"tags":["filesystem","name-collision","create","mkdir"],"backgroundTag":null,"analyzedSha":"1136503c6a231a16dce8f921f6fadb63d181e8db","analyzedAt":"2026-08-12T23:15:58.167Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}