usebruno/bruno · error · Error
directory: path is null
Error message
directory: path is null
What it means
Thrown by createDirectory when the dir argument is falsy. createDirectory is a thin wrapper over fs.mkdirSync with pre-conditions: it refuses null/undefined/empty-string paths and existing paths.
Source
Thrown at packages/bruno-electron/src/utils/filesystem.js:158
const hasBruExtension = (filename) => {
if (!filename || typeof filename !== 'string') return false;
return ['bru'].some((ext) => filename.toLowerCase().endsWith(`.${ext}`));
};
const hasRequestExtension = (filename, format = null) => {
if (!filename || typeof filename !== 'string') return false;
if (format) {
const ext = format === 'yml' ? 'yml' : 'bru';
return filename.toLowerCase().endsWith(`.${ext}`);
}
return ['bru', 'yml'].some((ext) => filename.toLowerCase().endsWith(`.${ext}`));
};
const createDirectory = async (dir) => {
if (!dir) {
throw new Error(`directory: path is null`);
}
if (fs.existsSync(dir)) {
throw new Error(`directory: ${dir} already exists`);
}
return fs.mkdirSync(dir);
};
const browseDirectory = async (win) => {
const { filePaths } = await dialog.showOpenDialog(win, {
properties: ['openDirectory', 'createDirectory']
});
if (!filePaths || !filePaths[0]) {
return false;
}
View on GitHub (pinned to 9bdd81c7bd)
Solutions
- Validate the path is a non-empty string at the call site before invoking createDirectory.
- Inspect the caller assembling dir — usually collectionPath or folderPath derived from undefined upstream.
- Return early from the user action if the path cannot be resolved.
Example fix
// before
const createDirectory = async (dir) => {
if (!dir) throw new Error('directory: path is null');
...
};
// after: caller guard
if (!dir || typeof dir !== 'string') {
throw new Error(`Refusing to create directory: invalid path ${String(dir)}`);
} Defensive patterns
Strategy: validation
Validate before calling
function safeCreateDirectory(dir) {
if (!dir || typeof dir !== 'string') {
throw new Error(`Refusing to create directory: invalid path ${String(dir)}`);
}
return createDirectory(dir);
} Type guard
function isNonEmptyPath(dir) {
return typeof dir === 'string' && dir.length > 0;
} Try / catch
try {
await createDirectory(dir);
} catch (err) {
if (err.message === 'directory: path is null') {
// upstream produced an empty path; re-resolve and retry once
dir = resolvePath();
if (!dir) throw err;
return createDirectory(dir);
}
throw err;
} Prevention
- Resolve and validate paths at the call site, not inside the primitive.
- Reject missing path fields in IPC payloads early.
- Add a type check soBuffers/objects never reach createDirectory.
When it happens
Trigger: Calling createDirectory(null), createDirectory(undefined), or createDirectory('') — usually because a path was assembled from a missing field (e.g. undefined parent + relative child collapsed to empty).
Common situations: IPC payload missing the directory field; race where the parent path is computed before the workspace is selected; refactor that dropped a path argument.
Related errors
- No files selected
- Invalid file type: ${file.name}. Only JSON files are support
- ${request.filename} is not a valid filename
- A file with the name "${finalFilename}" already exists in th
- environment: ${newEnvFilePath} already exists
AI-assisted analysis of usebruno/bruno@9bdd81c7bd (2026-08-13).
Data as JSON: /api/errors/e6b4ca221c26f2dd.
Report an issue: GitHub.