usebruno/bruno · warning · Error

A file with the name "${finalFilename}" already exists in th

Error message

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

What it means

Thrown by 'renderer:save-transient-request' when fs.existsSync(targetPathname) is true — i.e. a file with the computed finalFilename already exists in targetDirname. The handler computes finalFilename as `<basename without .bru/.yml>.<targetFormat>` and refuses to clobber an existing request file.

Source

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

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

      validatePathIsInsideCollection(targetDirname);

      const collectionPath = findCollectionPathByItemPath(targetDirname);
      if (!collectionPath) {
        throw new Error('Could not determine collection for target directory');
      }
      const targetFormat = getCollectionFormat(collectionPath);

      const filename = targetFilename || path.basename(sourcePathname);
      const filenameWithoutExt = filename.replace(/\.(bru|yml)$/, '');
      const finalFilename = `${filenameWithoutExt}.${targetFormat}`;
      const targetPathname = path.join(targetDirname, finalFilename);

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

      const actualSourceFormat = sourceFormat || 'yml';
      const needsConversion = actualSourceFormat !== targetFormat;

      let finalContent;
      if (needsConversion) {
        const { parseRequest, stringifyRequest } = require('@usebruno/filestore');
        const sourceContent = await fs.promises.readFile(sourcePathname, 'utf8');
        const parsedRequest = parseRequest(sourceContent, { format: actualSourceFormat });
        const mergedRequest = { ...parsedRequest, ...request };
        syncExampleUidsCache(sourcePathname, mergedRequest.examples);
        finalContent = stringifyRequest(mergedRequest, { format: targetFormat });
      } else {
        syncExampleUidsCache(sourcePathname, request.examples);
        finalContent = await stringifyRequestViaWorker(request, { format: targetFormat });
      }

View on GitHub (pinned to 9bdd81c7bd)

Solutions

  1. Generate a unique target filename (append ' (1)', ' (2)', etc.) before saving.
  2. Prompt the user to overwrite, rename, or skip; only overwrite via an explicit delete of the target first.
  3. Check fs.existsSync(targetPathname) in the UI before opening the save dialog.

Example fix

// before
await window.ipcRenderer.invoke('renderer:save-transient-request', { ..., targetFilename });

// after
let candidate = targetFilename;
let i = 1;
while (await window.ipcRenderer.invoke('renderer:file-exists', path.join(targetDirname, candidate))) {
  candidate = `${base} (${i++}).${format}`;
}
await window.ipcRenderer.invoke('renderer:save-transient-request', { ..., targetFilename: candidate });
Defensive patterns

Strategy: validation

Validate before calling

const candidate = path.join(targetDirname, finalFilename);
if (await window.ipcRenderer.invoke('renderer:file-exists', candidate)) {
  // prompt overwrite or generate a unique name
}

Try / catch

try {
  await window.ipcRenderer.invoke('renderer:save-transient-request', payload);
} catch (e) {
  if (/already exists in the target location/.test(e.message)) {
    payload.targetFilename = makeUnique(payload.targetFilename);
    await window.ipcRenderer.invoke('renderer:save-transient-request', payload);
  } else throw e;
}

Prevention

When it happens

Trigger: Moving/saving a transient request whose name collides with an existing request in the target folder. Two transient requests with the same name saved to the same folder. Case-insensitive filesystems (Windows/macOS) where 'Foo.bru' collides with 'foo.bru'.

Common situations: Duplicate request names across folders merged into one. Repeated save of a transient tab after one already landed. Case-fold collisions on macOS/Windows.

Related errors


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