usebruno/bruno · error · Error
Invalid scope type: ${scopeType}
Error message
Invalid scope type: ${scopeType} What it means
Thrown by the parseFileByType helper (used by 'renderer:update-variable-in-file') when scopeType is not one of 'request', 'folder', or 'collection'. The switch dispatches to parseRequestViaWorker / parseFolder / parseCollection and hits the default arm on any other value.
Source
Thrown at packages/bruno-electron/src/ipc/collection.js:679
}
await writeFile(pathname, content);
} catch (error) {
return Promise.reject(error);
}
});
// Helper: Parse file content based on scope type
const parseFileByType = async (fileContent, scopeType, format) => {
switch (scopeType) {
case 'request':
return await parseRequestViaWorker(fileContent, { format });
case 'folder':
return parseFolder(fileContent, { format });
case 'collection':
return parseCollection(fileContent, { format });
default:
throw new Error(`Invalid scope type: ${scopeType}`);
}
};
const stringifyByType = async (data, scopeType, collectionRoot, format) => {
switch (scopeType) {
case 'request':
return await stringifyRequestViaWorker(data, { format });
case 'folder':
return stringifyFolder(data, { format });
case 'collection':
return stringifyCollection(collectionRoot, data, { format });
default:
throw new Error(`Invalid scope type: ${scopeType}`);
}
};
// Helper: Update or create variable in array
const updateOrCreateVariable = (variables, variable) => {View on GitHub (pinned to 9bdd81c7bd)
Solutions
- Pass only 'request', 'folder', or 'collection' as scopeType.
- Define the allowed set as a shared constant/enum imported by both renderer and main.
- Validate scopeType against the allowed set on the renderer side before invoking the IPC.
Example fix
// before
await window.ipcRenderer.invoke('renderer:update-variable-in-file', pathname, variable, 'requests', root, format);
// after
const SCOPE = ['request', 'folder', 'collection'];
if (!SCOPE.includes(scopeType)) throw new Error(`bad scope: ${scopeType}`);
await window.ipcRenderer.invoke('renderer:update-variable-in-file', pathname, variable, scopeType, root, format); Defensive patterns
Strategy: type-guard
Validate before calling
const SCOPES = new Set(['request', 'folder', 'collection']);
if (!SCOPES.has(scopeType)) throw new Error(`unsupported scopeType: ${scopeType}`);
await window.ipcRenderer.invoke('renderer:update-variable-in-file', pathname, variable, scopeType, root, format); Type guard
function isScopeType(v) {
return v === 'request' || v === 'folder' || v === 'collection';
} Try / catch
try {
await window.ipcRenderer.invoke('renderer:update-variable-in-file', pathname, variable, scopeType, root, format);
} catch (e) {
if (/Invalid scope type/.test(e.message)) {
// log and surface a programming error to the developer
} else throw e;
} Prevention
- Share a single SCOPE_TYPE constant between renderer and main.
- Treat an invalid scopeType as a programming bug, not a user error — fail loud in dev.
- Re-run type checks after refactors that touch scope enums.
When it happens
Trigger: Invoking update-variable-in-file (or any handler using parseFileByType) with scopeType undefined, null, an empty string, a typo like 'requests' or 'Folder', or a future/unexpected value.
Common situations: A refactor that changes the scope constant set without updating callers. A typo in the renderer payload. An older renderer talking to a newer main process whose scope names diverged.
Related errors
- ${request.filename} is not a valid filename
- A file with the name "${finalFilename}" already exists in th
- environment: ${newEnvFilePath} already exists
- Invalid .env filename
- ${filename} file already exists
AI-assisted analysis of usebruno/bruno@9bdd81c7bd (2026-08-13).
Data as JSON: /api/errors/9e7b6882e98d0856.
Report an issue: GitHub.