usebruno/bruno · warning · Error

environment: ${newEnvFilePath} already exists

Error message

environment: ${newEnvFilePath} already exists

What it means

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.

Source

Thrown at packages/bruno-electron/src/ipc/collection.js:825

      });
    } catch (error) {
      return Promise.reject(error);
    }
  });

  // rename environment
  ipcMain.handle('renderer:rename-environment', async (event, collectionPathname, environmentName, newName) => {
    try {
      const format = getCollectionFormat(collectionPathname);
      const envFilePath = resolveEnvironmentFilePath(collectionPathname, environmentName, format);

      if (!fs.existsSync(envFilePath)) {
        throw new Error(`environment: ${envFilePath} does not exist`);
      }

      const newEnvFilePath = resolveEnvironmentFilePath(collectionPathname, newName, format);
      if (!safeToRename(envFilePath, newEnvFilePath)) {
        throw new Error(`environment: ${newEnvFilePath} already exists`);
      }

      moveRequestUid(envFilePath, newEnvFilePath);
      fs.renameSync(envFilePath, newEnvFilePath);

      environmentSecretsStore.renameEnvironment(collectionPathname, environmentName, newName);
    } catch (error) {
      return Promise.reject(error);
    }
  });

  // delete environment
  ipcMain.handle('renderer:delete-environment', async (event, collectionPathname, environmentName) => {
    try {
      const format = getCollectionFormat(collectionPathname);
      const envFilePath = resolveEnvironmentFilePath(collectionPathname, environmentName, format);
      if (!fs.existsSync(envFilePath)) {
        throw new Error(`environment: ${envFilePath} does not exist`);

View on GitHub (pinned to 9bdd81c7bd)

Solutions

  1. Check the desired new name is not already in the environments directory before renaming.
  2. Prompt the user to pick a unique name or overwrite (delete target first) explicitly.
  3. List existing environment names and validate against them in the UI.
Defensive patterns

Strategy: validation

Validate before calling

const existing = await window.ipcRenderer.invoke('renderer:list-environments', collectionPathname);
if (existing.some((e) => e.name.toLowerCase() === newName.toLowerCase())) {
  // pick a different name or prompt to overwrite
}

Try / catch

try {
  await window.ipcRenderer.invoke('renderer:rename-environment', collectionPathname, environmentName, newName);
} catch (e) {
  if (/already exists/.test(e.message)) {
    newName = await promptUniqueName();
    await window.ipcRenderer.invoke('renderer:rename-environment', collectionPathname, environmentName, newName);
  } else throw e;
}

Prevention

When it happens

Trigger: 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.

Common situations: User picks a duplicate name. Bulk operations that don't check for collisions first.

Related errors


AI-assisted analysis of usebruno/bruno@9bdd81c7bd (2026-08-13). Data as JSON: /api/errors/b89c03cc1c05700f. Report an issue: GitHub.