usebruno/bruno · warning · Error
Invalid format: ${format}
Error message
Invalid format: ${format} What it means
Thrown by searchForRequestFiles in the else-branch when format is not 'yml' or 'bru'. In practice this branch is unreachable: format comes from getCollectionFormat, which only returns 'yml' or 'bru' (or throws 'No collection configuration found' itself). The throw is defensive against a future change to getCollectionFormat's return set.
Source
Thrown at packages/bruno-electron/src/utils/filesystem.js:238
const stat = fs.statSync(filePath);
if (stat.isDirectory()) {
results = results.concat(searchForFiles(filePath, extension));
} else if (path.extname(file) === extension) {
results.push(filePath);
}
}
return results;
};
// Search for request files based on collection filetype by reading config
const searchForRequestFiles = (dir, collectionPath = null) => {
const format = getCollectionFormat(collectionPath || dir);
if (format === 'yml') {
return searchForFiles(dir, '.yml');
} else if (format === 'bru') {
return searchForFiles(dir, '.bru');
} else {
throw new Error(`Invalid format: ${format}`);
}
};
const sanitizeName = (name) => {
const invalidCharacters = /[<>:"/\\|?*\x00-\x1F]/g;
name = name
.replace(invalidCharacters, '-') // replace invalid characters with hyphens
.replace(/^[\s\-]+/, '') // remove leading spaces and hyphens
.replace(/[.\s]+$/, ''); // remove trailing dots and spaces
return name;
};
const isWindowsOS = () => {
return os.platform() === 'win32';
};
/**
* Generate a unique name by adding a "copy" suffix if neededView on GitHub (pinned to 9bdd81c7bd)
Solutions
- Treat as an invariant assertion; if it fires, sync the format switch in searchForRequestFiles with getCollectionFormat's return values.
- Add a test asserting searchForRequestFiles covers every value getCollectionFormat can return.
- If extending formats, update both functions together.
Example fix
// before
} else {
throw new Error(`Invalid format: ${format}`);
}
// after: exhaustive dispatch
switch (format) {
case 'yml': return searchForFiles(dir, '.yml');
case 'bru': return searchForFiles(dir, '.bru');
default: throw new Error(`searchForRequestFiles: unsupported format '${format}' from getCollectionFormat`);
} Defensive patterns
Strategy: validation
Validate before calling
// Defensive only: getCollectionFormat never returns a third value today.
// If you extend it, update this switch in lockstep.
const format = getCollectionFormat(dir);
assert(['yml', 'bru'].includes(format), `unexpected format ${format}`); Type guard
function isKnownCollectionFormat(format) {
return format === 'yml' || format === 'bru';
} Try / catch
try {
return searchForRequestFiles(dir, collectionPath);
} catch (err) {
if (err.message.startsWith('Invalid format')) {
// getCollectionFormat returned something new; fall back to .bru
return searchForFiles(dir, '.bru');
}
throw err;
} Prevention
- When extending getCollectionFormat, update searchForRequestFiles in the same commit.
- Add a test mapping every getCollectionFormat return value to a search branch.
- Treat the else-throw as an invariant, not an expected user error.
When it happens
Trigger: Effectively unreachable unless getCollectionFormat is modified to return a third value. Under current code, if neither opencollection.yml nor bruno.json exists, getCollectionFormat throws 'No collection configuration found' before this line is hit.
Common situations: Encountered only during refactors that extend getCollectionFormat with new formats without updating searchForRequestFiles; or if a caller bypasses getCollectionFormat and feeds a raw format through a different path.
Related errors
- path: ${itemPath} is not a valid request file
- path: ${oldPath} is not a valid request file
- Failed to export ${environmentType} environments.
- Failed to process ${parsedFile.fileName}: ${err.message}
- Failed to parse the file – ensure it is valid JSON or YAML
AI-assisted analysis of usebruno/bruno@9bdd81c7bd (2026-08-13).
Data as JSON: /api/errors/d3a6414368efe17d.
Report an issue: GitHub.