{"record":{"id":"e6b4ca221c26f2dd","repo":"usebruno/bruno","slug":"directory-path-is-null-e6b4ca","errorCode":null,"errorMessage":"directory: path is null","messagePattern":"directory: path is null","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/bruno-electron/src/utils/filesystem.js","lineNumber":158,"sourceCode":"const hasBruExtension = (filename) => {\n  if (!filename || typeof filename !== 'string') return false;\n  return ['bru'].some((ext) => filename.toLowerCase().endsWith(`.${ext}`));\n};\n\nconst hasRequestExtension = (filename, format = null) => {\n  if (!filename || typeof filename !== 'string') return false;\n\n  if (format) {\n    const ext = format === 'yml' ? 'yml' : 'bru';\n    return filename.toLowerCase().endsWith(`.${ext}`);\n  }\n\n  return ['bru', 'yml'].some((ext) => filename.toLowerCase().endsWith(`.${ext}`));\n};\n\nconst createDirectory = async (dir) => {\n  if (!dir) {\n    throw new Error(`directory: path is null`);\n  }\n\n  if (fs.existsSync(dir)) {\n    throw new Error(`directory: ${dir} already exists`);\n  }\n\n  return fs.mkdirSync(dir);\n};\n\nconst browseDirectory = async (win) => {\n  const { filePaths } = await dialog.showOpenDialog(win, {\n    properties: ['openDirectory', 'createDirectory']\n  });\n\n  if (!filePaths || !filePaths[0]) {\n    return false;\n  }\n","sourceCodeStart":140,"sourceCodeEnd":176,"githubUrl":"https://github.com/usebruno/bruno/blob/9bdd81c7bdc57006e5f5ebffb79321a8d979f712/packages/bruno-electron/src/utils/filesystem.js#L140-L176","documentation":"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.","triggerScenarios":"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).","commonSituations":"IPC payload missing the directory field; race where the parent path is computed before the workspace is selected; refactor that dropped a path argument.","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."],"exampleFix":"// before\nconst createDirectory = async (dir) => {\n  if (!dir) throw new Error('directory: path is null');\n  ...\n};\n\n// after: caller guard\nif (!dir || typeof dir !== 'string') {\n  throw new Error(`Refusing to create directory: invalid path ${String(dir)}`);\n}","handlingStrategy":"validation","validationCode":"function safeCreateDirectory(dir) {\n  if (!dir || typeof dir !== 'string') {\n    throw new Error(`Refusing to create directory: invalid path ${String(dir)}`);\n  }\n  return createDirectory(dir);\n}","typeGuard":"function isNonEmptyPath(dir) {\n  return typeof dir === 'string' && dir.length > 0;\n}","tryCatchPattern":"try {\n  await createDirectory(dir);\n} catch (err) {\n  if (err.message === 'directory: path is null') {\n    // upstream produced an empty path; re-resolve and retry once\n    dir = resolvePath();\n    if (!dir) throw err;\n    return createDirectory(dir);\n  }\n  throw err;\n}","preventionTips":["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."],"tags":["filesystem","validation","null-handling"],"backgroundTag":null,"analyzedSha":"9bdd81c7bdc57006e5f5ebffb79321a8d979f712","analyzedAt":"2026-08-13T04:09:25.751Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}