{"record":{"id":"1eab91c7093913d2","repo":"usebruno/bruno","slug":"failed-to-create-default-location","errorCode":null,"errorMessage":"Failed to create default location","messagePattern":"Failed to create default location","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"critical","filePath":"packages/bruno-electron/src/utils/default-location.js","lineNumber":26,"sourceCode":" * Returns the default location where new workspaces and collections are stored.\n * Checks ~/Documents/bruno if available, otherwise falls back to the app's data directory\n */\nfunction resolveDefaultLocation() {\n  const defaultPaths = [\n    path.join(app.getPath('documents'), BRUNO_DIR_NAME),\n    app.getPath('userData')\n  ];\n\n  for (const dirPath of defaultPaths) {\n    try {\n      fs.mkdirSync(dirPath, { recursive: true });\n      return dirPath;\n    } catch (error) {\n      console.warn(`Failed to create directory at ${dirPath}:`, error.message);\n    }\n  }\n\n  throw new Error('Failed to create default location');\n}\n\nmodule.exports = { resolveDefaultLocation };\n","sourceCodeStart":8,"sourceCodeEnd":30,"githubUrl":"https://github.com/usebruno/bruno/blob/9bdd81c7bdc57006e5f5ebffb79321a8d979f712/packages/bruno-electron/src/utils/default-location.js#L8-L30","documentation":"Thrown by resolveDefaultLocation when every candidate directory failed to create. Candidates are ~/Documents/bruno and the Electron userData dir; each is attempted with mkdirSync(recursive:true), and only if all throw does this fire. It signals a systemic inability to write to any user-writable location.","triggerScenarios":"Both app.getPath('documents') and app.getPath('userData') are unwritable (permissions, read-only mount, sandbox restriction, disk full, or documents path misconfigured on a headless/Linux system where XDG documents is unset).","commonSituations":"Snap/Flatpak sandbox denying Documents access; corporate-locked home directory; running with a restricted user; broken ELECTRON_USER_DATA_DIR override; disk-full condition.","solutions":["Check OS-level write permissions for the user's Documents and userData directories; grant write access or re-run with appropriate privileges.","On Linux without a Documents path, set XDG_DOCUMENTS_DIR or a valid app.getPath('documents') override.","Free disk space if the volume is full.","As a last resort, point Bruno's userData to a writable explicit location via app.setPath('userData', ...)."],"exampleFix":"// before\nfor (const dirPath of defaultPaths) {\n  try {\n    fs.mkdirSync(dirPath, { recursive: true });\n    return dirPath;\n  } catch (error) {\n    console.warn(`Failed to create directory at ${dirPath}:`, error.message);\n  }\n}\nthrow new Error('Failed to create default location');\n\n// after: include os.tmpdir() fallback and surface root cause\nconst defaultPaths = [\n  path.join(app.getPath('documents'), BRUNO_DIR_NAME),\n  app.getPath('userData'),\n  path.join(os.tmpdir(), BRUNO_DIR_NAME)\n];","handlingStrategy":"try-catch","validationCode":"function canWrite(dir) {\n  try { fs.accessSync(dir, fs.constants.W_OK); return true; } catch { return false; }\n}\nconst docs = app.getPath('documents');\nconst userData = app.getPath('userData');\nif (!canWrite(path.dirname(docs)) && !canWrite(userData)) {\n  throw new Error('No writable default location; check permissions');\n}","typeGuard":"function isWritableDir(dir) {\n  try { fs.mkdirSync(dir, { recursive: true }); return true; }\n  catch { return false; }\n}","tryCatchPattern":"try {\n  return resolveDefaultLocation();\n} catch (err) {\n  if (err.message === 'Failed to create default location') {\n    // prompt user to pick a writable directory, then app.setPath('userData', picked)\n    return await askUserForWritableLocation();\n  }\n  throw err;\n}","preventionTips":["Ensure the OS user has write access to Documents and userData before first launch.","On Linux, set XDG_DOCUMENTS_DIR and a running secret service.","For sandboxed installs (Snap/Flatpak), grant the filesystem permission."],"tags":["filesystem","permissions","startup","sandbox"],"backgroundTag":null,"analyzedSha":"9bdd81c7bdc57006e5f5ebffb79321a8d979f712","analyzedAt":"2026-08-13T04:09:25.751Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}