{"record":{"id":"760cc4f058eabbed","repo":"stablyai/orca","slug":"a-file-or-folder-named-name-already-exists-in","errorCode":null,"errorMessage":"A file or folder named '${name}' 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":37,"sourceCode":"import { authorizeExternalPath, resolveAuthorizedPath, isENOENT } from './filesystem-auth'\nimport { requireSshFilesystemProvider } from '../providers/ssh-filesystem-dispatch'\nimport { resolveLocalDroppedPathsForAgent } from './dropped-path-resolution'\nimport { importExternalPathsSsh } from './filesystem-import-ssh'\nimport type { SshMutationExpectation } from '../../shared/ssh-types'\nimport { assertSshMutationExpectation } from '../ssh/ssh-connection-generation'\nimport { renameLocalPathSerializedByDestination } from '../destination-serialized-local-rename'\n\n/**\n * Re-throw filesystem errors with user-friendly messages.\n * The `wx` flag on writeFile throws a raw EEXIST with no helpful message,\n * so we catch it here and provide context the renderer can display directly.\n */\nfunction rethrowWithUserMessage(error: unknown, targetPath: string): never {\n  const name = basename(targetPath)\n  if (error instanceof Error && 'code' in error) {\n    const code = (error as NodeJS.ErrnoException).code\n    if (code === 'EEXIST') {\n      throw new Error(`A file or folder named '${name}' already exists in this location`)\n    }\n    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 {","sourceCodeStart":19,"sourceCodeEnd":55,"githubUrl":"https://github.com/stablyai/orca/blob/1136503c6a231a16dce8f921f6fadb63d181e8db/src/main/ipc/filesystem-mutations.ts#L19-L55","documentation":"Thrown by rethrowWithUserMessage() when a createFile write (writeFile with flag 'wx') fails with errno code EEXIST. The 'wx' flag atomically refuses to overwrite, so EEXIST means the target path already existed at write time. rethrowWithUserMessage swaps the raw errno for a renderer-displayable message naming basename(targetPath).","triggerScenarios":"fs:createFile is invoked (locally) for a filePath that already exists as a file or folder; the race window in assertNotExists-style checks is closed by the atomic 'wx' flag, so this fires on a genuine pre-existing path or a concurrent creation that beat this call.","commonSituations":"User clicked 'New File' with a name already present in the folder; a duplicate creation attempt; two concurrent createFile calls for the same path; a folder with the same name as the file being created.","solutions":["Choose a different file name in the create action.","Delete or rename the existing entry first if overwrite is intended (note: createFile intentionally refuses to overwrite).","Deconflict the name in the renderer before issuing fs:createFile."],"exampleFix":"// before: await fs.createFile(`${dir}/${name}`) where name exists\n// after\nif (await fs.pathExists(`${dir}/${name}`)) {\n  name = await fs.uniqueName(dir, name)\n}\nawait fs.createFile(`${dir}/${name}`)","handlingStrategy":"validation","validationCode":"// Pre-check the path is free before createFile (atomic 'wx' is still authoritative)\nimport { lstat } from 'node:fs/promises'\nasync function pathIsFree(p: string): Promise<boolean> {\n  try { await lstat(p); return false } catch { return true }\n}","typeGuard":null,"tryCatchPattern":"try {\n  await window.api.fs.createFile({ filePath })\n} catch (e) {\n  if (e instanceof Error && /already exists/.test(e.message)) {\n    // prompt for a new name and retry\n  } else throw e\n}","preventionTips":["Deconflict file names in the UI before issuing createFile.","Handle the 'already exists' result gracefully with a rename prompt.","Remember createFile intentionally refuses to overwrite — never auto-retry unchanged."],"tags":["filesystem","name-collision","create","errno"],"backgroundTag":null,"analyzedSha":"1136503c6a231a16dce8f921f6fadb63d181e8db","analyzedAt":"2026-08-12T23:15:58.167Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}