usebruno/bruno · warning · Error

path: ${newPath} already exists

Error message

path: ${newPath} already exists

What it means

Thrown by 'renderer:rename-item-filename' when safeToRename(oldPath, newPath) returns false — i.e. newPath already exists and is not the same inode/birthtime as oldPath. The handler refuses to clobber an existing distinct file/folder.

Source

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

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

  // rename item
  ipcMain.handle('renderer:rename-item-filename', async (event, { oldPath, newPath, newName, newFilename, collectionPathname }) => {
    const tempDir = path.join(os.tmpdir(), `temp-folder-${Date.now()}`);
    const isWindowsOSAndNotWSLPathAndItemHasSubDirectories = isDirectory(oldPath) && isWindowsOS() && !isWSLPath(oldPath) && hasSubDirectories(oldPath);
    try {
      validatePathIsInsideCollection(oldPath);
      validatePathIsInsideCollection(newPath);

      // Check if the old path exists
      if (!fs.existsSync(oldPath)) {
        throw new Error(`path: ${oldPath} does not exist`);
      }

      if (!safeToRename(oldPath, newPath)) {
        throw new Error(`path: ${newPath} already exists`);
      }

      const format = getCollectionFormat(collectionPathname);

      if (isDirectory(oldPath)) {
        const folderFilePath = path.join(oldPath, `folder.${format}`);
        let folderFileJsonContent;
        if (fs.existsSync(folderFilePath)) {
          const oldFolderFileContent = await fs.promises.readFile(folderFilePath, 'utf8');
          folderFileJsonContent = await parseFolder(oldFolderFileContent, { format });
          folderFileJsonContent.meta.name = newName;
        } else {
          folderFileJsonContent = {
            meta: {
              name: newName
            }
          };
        }

View on GitHub (pinned to 9bdd81c7bd)

Solutions

  1. Pre-check for name collisions in the destination folder and auto-suggest a unique name (Bruno's generateUniqueName pattern).
  2. On case-insensitive FS, treat case-only renames specially or warn the user.
  3. Surface the existing-target conflict to the user with a 'replace / rename / cancel' choice.

Example fix

// before
await window.Ipc.invoke('renderer:rename-item-filename', { oldPath, newPath: path.join(dir, takenName), newName, newFilename, collectionPathname });

// after
const dir = path.dirname(oldPath);
let candidate = newFilename;
while (fs.existsSync(path.join(dir, candidate))) candidate = `${newFilename}-copy`;
await window.Ipc.invoke('renderer:rename-item-filename', { oldPath, newPath: path.join(dir, candidate), newName, newFilename: candidate, collectionPathname });
Defensive patterns

Strategy: validation

Validate before calling

const dir = path.dirname(oldPath);
if (fs.existsSyncSync?.(newPath) || (await window.ipc.invoke('main:path-exists', newPath))) {
  throw new Error(`'${path.basename(newPath)}' already exists in this folder`);
}

Type guard

function isNewPathSafe(safe: boolean): boolean { return safe; } // safeToRename result mirror

async function targetIsClear(p: string): Promise<boolean> {
  return !(await window.ipc.invoke('main:path-exists', p));
}

Try / catch

try {
  await window.Ipc.invoke('renderer:rename-item-filename', payload);
} catch (e) {
  if (String(e?.message).includes('already exists')) {
    payload.newFilename = await suggestUniqueName(payload.newFilename);
    await window.Ipc.invoke('renderer:rename-item-filename', payload);
  } else throw e;
}

Prevention

When it happens

Trigger: Choosing a new filename that collides with an existing item in the same folder, case-only rename on case-insensitive filesystems where both forms exist, or renaming to a name a sibling already holds.

Common situations: User typed a name already used by another request/folder, or two items differ only by case on macOS/Windows.

Related errors


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