usebruno/bruno · warning · Error

A file with the name "${targetFilename}" already exists in t

Error message

A file with the name "${targetFilename}" already exists in the target location

What it means

Thrown by 'renderer:move-item-cross-format' when fs.existsSync(targetPathname) is true after building targetPathname = targetDirname/<basename>.<targetExt>. The handler will not overwrite an existing request file in the destination.

Source

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

    try {
      if (!fs.existsSync(sourcePathname)) {
        throw new Error(`Source path: ${sourcePathname} does not exist`);
      }
      if (!fs.existsSync(targetDirname)) {
        throw new Error(`Target directory: ${targetDirname} does not exist`);
      }

      validatePathIsInsideCollection(sourcePathname);
      validatePathIsInsideCollection(targetDirname);

      const sourceBasename = path.basename(sourcePathname);
      const filenameWithoutExt = sourceBasename.replace(/\.(bru|yml|yaml)$/, '');
      const targetExt = targetFormat === 'yml' ? 'yml' : 'bru';
      const targetFilename = `${filenameWithoutExt}.${targetExt}`;
      const targetPathname = path.join(targetDirname, targetFilename);

      if (fs.existsSync(targetPathname)) {
        throw new Error(`A file with the name "${targetFilename}" already exists in the target location`);
      }

      const sourceContent = await fs.promises.readFile(sourcePathname, 'utf8');
      const parsedRequest = parseRequest(sourceContent, { format: sourceFormat });
      const finalContent = stringifyRequest(parsedRequest, { format: targetFormat });

      await writeFile(targetPathname, finalContent);
      await removePath(sourcePathname);

      moveRequestUid(sourcePathname, targetPathname);

      return { newPathname: targetPathname };
    } catch (error) {
      return Promise.reject(error);
    }
  });

  ipcMain.handle('renderer:move-folder-item', async (event, folderPath, destinationPath) => {

View on GitHub (pinned to 9bdd81c7bd)

Solutions

  1. Pre-check for a colliding target filename and either auto-rename or prompt the user.
  2. If the existing file is a stale migration artifact, remove it before the move.
  3. Use generateUniqueName to derive a non-colliding target filename.

Example fix

// before
await window.Ipc.invoke('renderer:move-item-cross-format', { targetDirname, sourcePathname, sourceFormat, targetFormat });

// after
// compute target up front and rename on collision (caller-side) or extend handler to accept a force/overwrite flag
const targetExt = targetFormat === 'yml' ? 'yml' : 'bru';
let targetPathname = path.join(targetDirname, `${base}.${targetExt}`);
if (fs.existsSync(targetPathname)) targetPathname = path.join(targetDirname, `${base}-copy.${targetExt}`);
// pass explicit target via an extended payload if supported, or pre-resolve by renaming source first
Defensive patterns

Strategy: validation

Validate before calling

const targetExt = targetFormat === 'yml' ? 'yml' : 'bru';
const base = sourcePathname.replace(/\.(bru|yml|yaml)$/, '');
const targetPathname = path.join(targetDirname, `${path.basename(base)}.${targetExt}`);
if (await window.ipc.invoke('main:path-exists', targetPathname)) {
  throw new Error(`a ${targetExt} file with that name already exists in the target`);
}

Type guard

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

Try / catch

try {
  await window.Ipc.invoke('renderer:move-item-cross-format', payload);
} catch (e) {
  if (String(e?.message).includes('already exists in the target')) {
    // rename source first or pick a different target filename and retry
    await suggestAlternateNameAndRetry(payload);
  } else throw e;
}

Prevention

When it happens

Trigger: Moving a request whose base name (minus extension) matches an existing file in the target folder, especially common during cross-format moves where 'req.bru' and 'req.yml' derive the same target filename.

Common situations: Same-named request exists in the target format, partial migration left a converted file behind, or duplicate filenames across folders being merged.

Related errors


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