{"record":{"id":"b89c03cc1c05700f","repo":"usebruno/bruno","slug":"environment-newenvfilepath-already-exists","errorCode":null,"errorMessage":"environment: ${newEnvFilePath} already exists","messagePattern":"environment: (.+?) already exists","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"warning","filePath":"packages/bruno-electron/src/ipc/collection.js","lineNumber":825,"sourceCode":"      });\n    } catch (error) {\n      return Promise.reject(error);\n    }\n  });\n\n  // rename environment\n  ipcMain.handle('renderer:rename-environment', async (event, collectionPathname, environmentName, newName) => {\n    try {\n      const format = getCollectionFormat(collectionPathname);\n      const envFilePath = resolveEnvironmentFilePath(collectionPathname, environmentName, format);\n\n      if (!fs.existsSync(envFilePath)) {\n        throw new Error(`environment: ${envFilePath} does not exist`);\n      }\n\n      const newEnvFilePath = resolveEnvironmentFilePath(collectionPathname, newName, format);\n      if (!safeToRename(envFilePath, newEnvFilePath)) {\n        throw new Error(`environment: ${newEnvFilePath} already exists`);\n      }\n\n      moveRequestUid(envFilePath, newEnvFilePath);\n      fs.renameSync(envFilePath, newEnvFilePath);\n\n      environmentSecretsStore.renameEnvironment(collectionPathname, environmentName, newName);\n    } catch (error) {\n      return Promise.reject(error);\n    }\n  });\n\n  // delete environment\n  ipcMain.handle('renderer:delete-environment', async (event, collectionPathname, environmentName) => {\n    try {\n      const format = getCollectionFormat(collectionPathname);\n      const envFilePath = resolveEnvironmentFilePath(collectionPathname, environmentName, format);\n      if (!fs.existsSync(envFilePath)) {\n        throw new Error(`environment: ${envFilePath} does not exist`);","sourceCodeStart":807,"sourceCodeEnd":843,"githubUrl":"https://github.com/usebruno/bruno/blob/9bdd81c7bdc57006e5f5ebffb79321a8d979f712/packages/bruno-electron/src/ipc/collection.js#L807-L843","documentation":"Thrown by 'renderer:rename-environment' when safeToRename(envFilePath, newEnvFilePath) returns false. safeToRename returns false when the target path already and is a different file from the source (so case-only renames on case-insensitive filesystems are allowed). The target name is also validated by resolveEnvironmentFilePath, so path separators in newName fail earlier with a different message.","triggerScenarios":"Renaming an environment to a name that already exists in the collection. Two environments differing only in casing on a case-sensitive filesystem. Attempting to rename onto an existing target.","commonSituations":"User picks a duplicate name. Bulk operations that don't check for collisions first.","solutions":["Check the desired new name is not already in the environments directory before renaming.","Prompt the user to pick a unique name or overwrite (delete target first) explicitly.","List existing environment names and validate against them in the UI."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"const existing = await window.ipcRenderer.invoke('renderer:list-environments', collectionPathname);\nif (existing.some((e) => e.name.toLowerCase() === newName.toLowerCase())) {\n  // pick a different name or prompt to overwrite\n}","typeGuard":null,"tryCatchPattern":"try {\n  await window.ipcRenderer.invoke('renderer:rename-environment', collectionPathname, environmentName, newName);\n} catch (e) {\n  if (/already exists/.test(e.message)) {\n    newName = await promptUniqueName();\n    await window.ipcRenderer.invoke('renderer:rename-environment', collectionPathname, environmentName, newName);\n  } else throw e;\n}","preventionTips":["Validate the new name against existing environment names (case-insensitively) before renaming.","Block path separators in environment names so resolveEnvironmentFilePath does not reject them earlier."],"tags":["ipc","filesystem","environment","validation","bruno"],"backgroundTag":null,"analyzedSha":"9bdd81c7bdc57006e5f5ebffb79321a8d979f712","analyzedAt":"2026-08-13T04:09:25.751Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}