usebruno/bruno · error · Error
Invalid collection format: ${format}
Error message
Invalid collection format: ${format} What it means
Thrown defensively by writeBrunoConfig when getCollectionFormat returns a value that is neither 'bru' nor 'yml'. Because getCollectionFormat itself only ever returns 'yml' (opencollection.yml present), 'bru' (bruno.json present), or throws its own 'No collection configuration found' error, this branch is an invariant guard: it fires only if the format detection contract has been broken (e.g. a new format was added to getCollectionFormat without a matching write branch) or if collectionPath was mutated between detection and write.
Source
Thrown at packages/bruno-electron/src/ipc/collection.js:1790
const brunoConfigPath = path.join(collectionPath, 'bruno.json');
const content = await stringifyJson(transformedBrunoConfig);
await writeFile(brunoConfigPath, content);
} else if (format === 'yml') {
// opencollection.yml holds both config AND the collection root. If the caller
// didn't supply a root (e.g. a config-only update before the tree finished
// loading), recover it from disk so request defaults/docs/scripts aren't wiped.
let rootToWrite = collectionRoot;
if (!rootToWrite) {
const ocYmlPath = path.join(collectionPath, 'opencollection.yml');
if (fs.existsSync(ocYmlPath)) {
const existing = fs.readFileSync(ocYmlPath, 'utf8');
rootToWrite = parseCollection(existing, { format }).collectionRoot;
}
}
const content = await stringifyCollection(rootToWrite, transformedBrunoConfig, { format });
await writeFile(path.join(collectionPath, 'opencollection.yml'), content);
} else {
throw new Error(`Invalid collection format: ${format}`);
}
};
ipcMain.handle('renderer:update-bruno-config', async (event, brunoConfig, collectionPath, collectionRoot) => {
try {
await writeBrunoConfig(brunoConfig, collectionPath, collectionRoot);
} catch (error) {
return Promise.reject(error);
}
});
ipcMain.handle('renderer:ignore-folder', async (event, collectionUid, collectionPath, collectionRoot, brunoConfig, folderPath) => {
try {
const relativePath = path.relative(collectionPath, folderPath).replace(/\\/g, '/');
const existingIgnores = brunoConfig?.ignore || [];
const updatedBrunoConfig = {
...brunoConfig,
ignore: [...new Set([...existingIgnores, relativePath])]View on GitHub (pinned to 9bdd81c7bd)
Solutions
- If you are a user: confirm the collection directory contains either bruno.json or opencollection.yml; if neither, re-save the collection from the UI.
- If you are extending formats: add an `else if (format === '<new>')` branch to writeBrunoConfig mirroring the existing yml/bru write logic.
- Audit getCollectionFormat (utils/filesystem.js:277) and writeBrunoConfig together so the two stay in sync; add a unit test covering the new format.
Example fix
// before
} else {
throw new Error(`Invalid collection format: ${format}`);
}
// after
} else if (format === 'json') {
const content = await stringifyJson(transformedBrunoConfig);
await writeFile(path.join(collectionPath, 'collection.json'), content);
} else {
throw new Error(`Invalid collection format: ${format}`);
} Defensive patterns
Strategy: validation
Validate before calling
const fs = require('fs');
const path = require('path');
function detectFormat(collectionPath) {
if (fs.existsSync(path.join(collectionPath, 'opencollection.yml'))) return 'yml';
if (fs.existsSync(path.join(collectionPath, 'bruno.json'))) return 'bru';
return null;
}
// before invoking renderer:update-bruno-config
const fmt = detectFormat(collectionPath);
if (fmt !== 'bru' && fmt !== 'yml') {
throw new Error(`Refusing to update: unsupported or missing format for ${collectionPath}`);
} Type guard
/** @param {string} f @returns {f is 'bru' | 'yml'} */
function isSupportedFormat(f) {
return f === 'bru' || f === 'yml';
} Prevention
- Keep getCollectionFormat (utils/filesystem.js:277) and writeBrunoConfig branch lists in sync; add a unit test per format.
- Only call renderer:update-bruno-config on collections that contain bruno.json or opencollection.yml.
- Treat 'Invalid collection format' as a programmer error, not a user-facing one — file a bug when it fires.
When it happens
Trigger: Invoking IPC renderer:update-bruno-config (or any internal caller of writeBrunoConfig) on a collection whose detected format is a value other than 'bru' or 'yml'. In practice unreachable unless getCollectionFormat is extended without updating this switch, or the format string is externally overridden.
Common situations: A maintainer adds a third collection format to getCollectionFormat (filesystem.js:277) but forgets a branch in writeBrunoConfig; mid-refactor state where one of bruno.json/opencollection.yml is removed between the getCollectionFormat call and the if/else.
Related errors
- Failed to export ${environmentType} environments.
- Could not reach the mock server
- Mock server id is required.
- Workspace path is required.
- ${request.filename} is not a valid filename
AI-assisted analysis of usebruno/bruno@9bdd81c7bd (2026-08-13).
Data as JSON: /api/errors/698db451ac2e8955.
Report an issue: GitHub.