usebruno/bruno · error · Error
Invalid collection: name and path are required
Error message
Invalid collection: name and path are required
What it means
`addCollectionToWorkspace` runs `isValidCollectionEntry`, which requires an object with non-empty trimmed `name` and `path` strings; otherwise it throws before acquiring the workspace lock.
Source
Thrown at packages/bruno-electron/src/utils/workspace-config.js:339
const yamlContent = generateYamlContent(config);
await writeWorkspaceFileAtomic(workspacePath, yamlContent);
return config;
});
};
const updateWorkspaceDocs = async (workspacePath, docs) => {
return withLock(getWorkspaceLockKey(workspacePath), async () => {
const config = readWorkspaceConfig(workspacePath);
config.docs = docs;
const yamlContent = generateYamlContent(config);
await writeWorkspaceFileAtomic(workspacePath, yamlContent);
return docs;
});
};
const addCollectionToWorkspace = async (workspacePath, collection) => {
if (!isValidCollectionEntry(collection)) {
throw new Error('Invalid collection: name and path are required');
}
return withLock(getWorkspaceLockKey(workspacePath), async () => {
const config = readWorkspaceConfig(workspacePath);
if (!config.collections) {
config.collections = [];
}
const normalizedCollection = {
name: collection.name.trim(),
path: posixifyPath(collection.path.trim())
};
if (collection.remote && typeof collection.remote === 'string') {
normalizedCollection.remote = collection.remote.trim();
}
View on GitHub (pinned to 9bdd81c7bd)
Solutions
- Ensure `collection.name` is a non-empty trimmed string.
- Ensure `collection.path` is a non-empty trimmed string (absolute or resolvable).
- Build the entry through a factory that fills both fields, validating before submit.
Example fix
// before
await addCollectionToWorkspace(wsPath, { name: 'API' });
// after
await addCollectionToWorkspace(wsPath, { name: 'API', path: '/work/ws/api' }); Defensive patterns
Strategy: validation
Validate before calling
function isValidCollectionEntry(c) {
return !!c && typeof c === 'object'
&& typeof c.name === 'string' && c.name.trim() !== ''
&& typeof c.path === 'string' && c.path.trim() !== '';
}
if (!isValidCollectionEntry(entry)) throw new Error('name and path required'); Type guard
function isCollectionEntry(c: unknown): c is { name: string; path: string } {
if (!c || typeof c !== 'object') return false;
const o = c as any;
return typeof o.name === 'string' && o.name.trim() !== ''
&& typeof o.path === 'string' && o.path.trim() !== '';
} Prevention
- Disable the submit button until both fields are non-empty.
- Resolve paths to absolute strings before constructing the entry.
When it happens
Trigger: Calling `addCollectionToWorkspace(workspacePath, collection)` where `collection` is not an object, or where `name`/`path` is missing, empty, or non-string.
Common situations: UI form submitted with a blank collection name or path; a programmatic caller that built the entry with undefined fields; passing a relative path that got normalized to empty; copy of an entry that lost fields.
Related errors
- Workspace path is required
- Workspace configuration must be an object
- Invalid workspace: not a bruno workspace
- Workspace must have a valid name
- A non-empty Git remote URL is required
AI-assisted analysis of usebruno/bruno@9bdd81c7bd (2026-08-13).
Data as JSON: /api/errors/b5e0dc3ff42e4a66.
Report an issue: GitHub.