{"record":{"id":"48e24eb729869286","repo":"garrytan/gstack","slug":"cannot-create-state-directory-config-statedir-48e24e","errorCode":null,"errorMessage":"Cannot create state directory ${config.stateDir}: a file exists at that path","messagePattern":"Cannot create state directory (.+?): a file exists at that path","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"browse/src/config.ts","lineNumber":93,"sourceCode":"    networkLog: path.join(stateDir, 'browse-network.log'),\n    dialogLog: path.join(stateDir, 'browse-dialog.log'),\n    auditLog: path.join(stateDir, 'browse-audit.jsonl'),\n  };\n}\n\n/**\n * Create the .gstack/ state directory if it doesn't exist.\n * Throws with a clear message on permission errors.\n */\nexport function ensureStateDir(config: BrowseConfig): void {\n  try {\n    mkdirSecure(config.stateDir);\n  } catch (err: any) {\n    if (err.code === 'EACCES') {\n      throw new Error(`Cannot create state directory ${config.stateDir}: permission denied`);\n    }\n    if (err.code === 'ENOTDIR') {\n      throw new Error(`Cannot create state directory ${config.stateDir}: a file exists at that path`);\n    }\n    throw err;\n  }\n\n  // Ensure .gstack/ is in the project's .gitignore\n  const gitignorePath = path.join(config.projectDir, '.gitignore');\n  try {\n    const content = fs.readFileSync(gitignorePath, 'utf-8');\n    if (!content.match(/^\\.gstack\\/?$/m)) {\n      const separator = content.endsWith('\\n') ? '' : '\\n';\n      fs.appendFileSync(gitignorePath, `${separator}.gstack/\\n`);\n    }\n  } catch (err: any) {\n    if (err.code !== 'ENOENT') {\n      // Write warning to server log (visible even in daemon mode)\n      const logPath = path.join(config.stateDir, 'browse-server.log');\n      try {\n        fs.appendFileSync(logPath, `[${new Date().toISOString()}] Warning: could not update .gitignore at ${gitignorePath}: ${err.message}\\n`);","sourceCodeStart":75,"sourceCodeEnd":111,"githubUrl":"https://github.com/garrytan/gstack/blob/94993f74012782fd94416dd44b8314f6363a13a4/browse/src/config.ts#L75-L111","documentation":"Error \"Cannot create state directory ${config.stateDir}: a file exists at that path\" thrown in garrytan/gstack.","triggerScenarios":"Thrown at browse/src/config.ts:93 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"94993f74012782fd94416dd44b8314f6363a13a4","analyzedAt":"2026-08-12T04:06:23.140Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}