usebruno/bruno · error · Error
Invalid format: ${format}
Error message
Invalid format: ${format} What it means
Thrown by importCollection when the format argument is neither 'yml' nor 'bru'. The function defaults format to DEFAULT_COLLECTION_FORMAT, so this branch only fires if a caller explicitly passes an unsupported value.
Source
Thrown at packages/bruno-electron/src/utils/collection-import.js:125
if (format === 'yml') {
brunoConfig.opencollection = '1.0.0';
const collectionContent = await stringifyCollection(collection.root, brunoConfig, { format });
await writeFile(path.join(collectionPath, 'opencollection.yml'), collectionContent);
} else if (format === 'bru') {
const bruJsonConfig = { ...brunoConfig, version: '1' };
if (brunoConfig.version) {
bruJsonConfig.collectionVersion = brunoConfig.version;
} else {
delete bruJsonConfig.collectionVersion;
}
const stringifiedBrunoConfig = await stringifyJson(bruJsonConfig);
await writeFile(path.join(collectionPath, 'bruno.json'), stringifiedBrunoConfig);
const collectionContent = await stringifyCollection(collection.root, brunoConfig, { format });
await writeFile(path.join(collectionPath, 'collection.bru'), collectionContent);
} else {
throw new Error(`Invalid format: ${format}`);
}
const { size, filesCount } = await getCollectionStats(collectionPath);
brunoConfig.size = size;
brunoConfig.filesCount = filesCount;
// Send collection-opened event unless caller wants to handle it themselves (e.g., during onboarding)
if (!options.skipOpenEvent) {
mainWindow.webContents.send('main:collection-opened', collectionPath, uid, brunoConfig);
ipcMain.emit('main:collection-opened', mainWindow, collectionPath, uid, brunoConfig);
}
// create folder and files based on collection
await parseCollectionItems(collection.items, collectionPath);
await parseEnvironments(collection.environments, collectionPath);
return { collectionPath, uid, brunoConfig };
}View on GitHub (pinned to 9bdd81c7bd)
Solutions
- Whitelist format to 'bru' | 'yml' at the IPC boundary and reject unknown values before importCollection.
- Fall back to DEFAULT_COLLECTION_FORMAT when format is missing or unsupported rather than throwing mid-write.
- Ensure the renderer/import dialog only offers the two supported formats.
Example fix
// before
} else {
throw new Error(`Invalid format: ${format}`);
}
// after: coerce at entry
const SUPPORTED = new Set(['bru', 'yml']);
const safeFormat = SUPPORTED.has(format) ? format : DEFAULT_COLLECTION_FORMAT; Defensive patterns
Strategy: validation
Validate before calling
const SUPPORTED_FORMATS = new Set(['bru', 'yml']); const safeFormat = SUPPORTED_FORMATS.has(format) ? format : DEFAULT_COLLECTION_FORMAT; await importCollection(collection, collectionLocation, mainWindow, uniqueFolderName, safeFormat, options);
Type guard
function isSupportedFormat(format) {
return format === 'bru' || format === 'yml';
} Try / catch
try {
await importCollection(collection, collectionLocation, mainWindow, uniqueFolderName, format, options);
} catch (err) {
if (err.message.startsWith('Invalid format')) {
return importCollection(collection, collectionLocation, mainWindow, uniqueFolderName, DEFAULT_COLLECTION_FORMAT, options);
}
throw err;
} Prevention
- Allow-list the format at the IPC boundary.
- Default to DEFAULT_COLLECTION_FORMAT when the value is missing.
- Have the import dialog only expose the two supported formats.
When it happens
Trigger: Calling importCollection(..., format) with undefined replaced by an invalid string, or a format value from an unversioned import source (e.g. a legacy 'json' format) that the writer does not support.
Common situations: Forwarding an unvalidated format from a file-picker/CLI/import-dialog; version skew between the importer UI and the supported formats; passing null which then bypasses the default param.
Related errors
- Invalid environment: expected an object
- Invalid environment: missing or invalid variables array
- Invalid variable at index ${index}: expected an object
- Invalid variable at index ${index}: missing or invalid name
- No files provided
AI-assisted analysis of usebruno/bruno@9bdd81c7bd (2026-08-13).
Data as JSON: /api/errors/862eb270ddca2a6c.
Report an issue: GitHub.