{"record":{"id":"ecfa556795f509ef","repo":"garrytan/gstack","slug":"gbrain-not-configured-run-setup-gbrain","errorCode":null,"errorMessage":"gbrain not configured (run /setup-gbrain)","messagePattern":"gbrain not configured \\(run /setup-gbrain\\)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"lib/gbrain-sources.ts","lineNumber":134,"sourceCode":" */\nexport function probeSource(id: string, env?: NodeJS.ProcessEnv): SourceState {\n  let stdout: string;\n  try {\n    stdout = execFileSync(\"gbrain\", [\"sources\", \"list\", \"--json\"], {\n      encoding: \"utf-8\",\n      timeout: 30_000,\n      stdio: [\"ignore\", \"pipe\", \"pipe\"],\n      env,\n      shell: NEEDS_SHELL_ON_WINDOWS, // #1731: gbrain is a .cmd shim on Windows\n    });\n  } catch (err) {\n    const e = err as NodeJS.ErrnoException & { stderr?: Buffer };\n    const stderr = e.stderr?.toString() || \"\";\n    if (e.code === \"ENOENT\" || stderr.includes(\"command not found\")) {\n      throw new Error(\"gbrain CLI not on PATH\");\n    }\n    if (stderr.includes(\"Cannot connect to database\") || stderr.includes(\"config.json\")) {\n      throw new Error(\"gbrain not configured (run /setup-gbrain)\");\n    }\n    throw err;\n  }\n\n  let parsed: unknown;\n  try {\n    parsed = JSON.parse(stdout);\n  } catch (err) {\n    throw new Error(`gbrain sources list returned non-JSON output: ${(err as Error).message}`);\n  }\n\n  const sources = parseSourcesList(parsed);\n  const match = sources.find((s) => s.id === id);\n  if (!match) return { status: \"absent\" };\n  return {\n    status: \"match\",\n    registered_path: match.local_path,\n  };","sourceCodeStart":116,"sourceCodeEnd":152,"githubUrl":"https://github.com/garrytan/gstack/blob/94993f74012782fd94416dd44b8314f6363a13a4/lib/gbrain-sources.ts#L116-L152","documentation":"Thrown by probeSource() when gbrain ran (spawn succeeded) but its stderr indicates a configuration problem: 'Cannot connect to database' or a reference to 'config.json'. This means gbrain is installed but has not been initialized — the user needs to run /setup-gbrain to create its config and database before any sources command can work. Like 316, callers are expected to treat this as 'absent, skip stage' for non-fatal flows.","triggerScenarios":"gbrain sources list --json exits non-zero with stderr containing 'Cannot connect to database' or 'config.json'. The CLI binary exists but its backing database/config is missing or unreadable.","commonSituations":"gbrain installed but /setup-gbrain never run; the database file was deleted or moved; config.json corrupted or points at an unreachable DB path; permissions on the gbrain config dir prevent reading.","solutions":["Run /setup-gbrain to initialize gbrain's config and database.","If config.json exists but is broken, back it up and re-run setup to regenerate.","Check permissions on gbrain's config/data directory (usually ~/.gbrain or similar).","Verify the database path in config.json resolves and is writable."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"import { execFileSync } from 'child_process';\nfunction gbrainConfigured(env: NodeJS.ProcessEnv = process.env): boolean {\n  try {\n    execFileSync('gbrain', ['sources', 'list', '--json'], { encoding: 'utf-8', env, stdio: 'ignore', timeout: 5_000 });\n    return true;\n  } catch (e: any) {\n    const stderr = e.stderr?.toString() ?? '';\n    return !stderr.includes('Cannot connect to database') && !stderr.includes('config.json');\n  }\n}","typeGuard":null,"tryCatchPattern":"try {\n  return probeSource(id, env);\n} catch (e) {\n  if (e instanceof Error && e.message === 'gbrain not configured (run /setup-gbrain)') {\n    return { status: 'absent' }; // skip stage, prompt user to run setup\n  }\n  throw e;\n}","preventionTips":["Run /setup-gbrain once per environment to initialize config + DB.","Verify config.json path and DB permissions after setup.","Back up gbrain's config before OS migrations.","Treat this as a skip-stage signal in non-fatal sync flows."],"tags":["gbrain","config","database","setup"],"backgroundTag":null,"analyzedSha":"94993f74012782fd94416dd44b8314f6363a13a4","analyzedAt":"2026-08-12T04:06:23.140Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}