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

  1. Validate the path is a non-empty string at the call site before invoking createDirectory.
  2. Inspect the caller assembling dir — usually collectionPath or folderPath derived from undefined upstream.
  3. 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

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


AI-assisted analysis of usebruno/bruno@9bdd81c7bd (2026-08-13). Data as JSON: /api/errors/e6b4ca221c26f2dd. Report an issue: GitHub.