usebruno/bruno · warning · Error

Single object export requires exactly one environment

Error message

Single object export requires exactly one environment

What it means

Thrown by 'renderer:export-environment' when exportFormat is 'single-object' but the environments array does not have exactly one entry. The single-object format writes one JSON file representing one environment, so zero or multiple environments are rejected.

Solutions

  1. Switch the user to 'folder' export when more than one environment is selected.
  2. Disable the single-object option in the UI unless exactly one environment is selected.
  3. Reduce the selection to one environment before invoking.

Example fix

// before
await window.Ipc.invoke('renderer:export-environment', { environments: allEnvs, environmentType, filePath, exportFormat: 'single-object' });

// after
const fmt = selectedEnvs.length === 1 ? 'single-object' : 'folder';
await window.Ipc.invoke('renderer:export-environment', { environments: selectedEnvs, environmentType, filePath, exportFormat: fmt });
Defensive patterns

Strategy: validation

Validate before calling

if (exportFormat === 'single-object' && environments.length !== 1) {
  throw new Error('Select exactly one environment for single-object export');
}
await window.Ipc.invoke('renderer:export-environment', { environments, environmentType, filePath, exportFormat });

Type guard

function canSingleObjectExport(environments: unknown[], fmt: string): boolean {
  return fmt !== 'single-object' || (Array.isArray(environments) && environments.length === 1);
}

Prevention

When it happens

Trigger: Selecting 'single object' export with a multi-select of environments, or with none selected; passing an array of length 0 or >= 2 with exportFormat: 'single-object'.

Common situations: UI exposes a 'select all + single-file' combination, batch export menu defaults to multi-select, or the user changed selection after picking the format.

Related errors


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

Appendix: source

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

        const baseFileName = `bruno-${environmentType}-environments`;
        const uniqueFileName = generateUniqueName(baseFileName, (name) => fs.existsSync(path.join(filePath, `${name}.json`)));
        const fullPath = path.join(filePath, `${uniqueFileName}.json`);

        const exportData = {
          info: {
            type: 'bruno-environment',
            exportedAt: new Date().toISOString(),
            exportedUsing: `Bruno/v${appVersion}`
          },
          environments
        };

        const jsonContent = JSON.stringify(exportData, null, 2);
        await fs.promises.writeFile(fullPath, jsonContent, 'utf8');
      } else if (exportFormat === 'single-object') {
        // single environment json file
        if (environments.length !== 1) {
          throw new Error('Single object export requires exactly one environment');
        }

        const environment = environments[0];
        const baseFileName = environment.name ? `${environment.name.replace(/[^a-zA-Z0-9-_]/g, '_')}` : 'environment';
        const uniqueFileName = generateUniqueName(baseFileName, (name) => fs.existsSync(path.join(filePath, `${name}.json`)));
        const fullPath = path.join(filePath, `${uniqueFileName}.json`);
        const jsonContent = JSON.stringify(environmentWithInfo(environment), null, 2);
        await fs.promises.writeFile(fullPath, jsonContent, 'utf8');
      } else {
        throw new Error(`Unsupported export format: ${exportFormat}`);
      }
    } catch (error) {
      return Promise.reject(error);
    }
  });

  // rename item
  ipcMain.handle('renderer:rename-item-name', async (event, { itemPath, newName, collectionPathname }) => {

View on GitHub (pinned to 9bdd81c7bd)