{"record":{"id":"6a84faad10b2ea83","repo":"gastownhall/beads","slug":"no-database-connection-available-s","errorCode":null,"errorMessage":"no database connection available (%s)","messagePattern":"no database connection available \\((.+?)\\)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/bd/batch.go","lineNumber":100,"sourceCode":"NOTE: This is a narrow subset. Commands like 'show', 'list', 'ready', 'sync',\ncomplex create flows, or any flag not listed above are NOT accepted. Use\nnormal 'bd' subcommands for interactive/read operations.`,\n\tArgs:          cobra.NoArgs,\n\tSilenceUsage:  true,\n\tSilenceErrors: false,\n\tRunE: func(cmd *cobra.Command, args []string) error {\n\t\tCheckReadonly(\"batch\")\n\n\t\tevt := metrics.NewCommandEvent(\"batch\")\n\t\tdefer func() {\n\t\t\tif c := metrics.Global(); c != nil {\n\t\t\t\tc.CloseEventAndAdd(evt)\n\t\t\t}\n\t\t}()\n\n\t\tproxied := usesProxiedServer()\n\t\tif !proxied && store == nil {\n\t\t\treturn fmt.Errorf(\"no database connection available (%s)\", diagHint())\n\t\t}\n\n\t\tfilePath, _ := cmd.Flags().GetString(\"file\")\n\t\tdryRun, _ := cmd.Flags().GetBool(\"dry-run\")\n\t\tcommitMsg, _ := cmd.Flags().GetString(\"message\")\n\n\t\tvar reader io.Reader\n\t\tif filePath != \"\" {\n\t\t\tf, err := os.Open(filePath) // #nosec G304 -- user-supplied batch file\n\t\t\tif err != nil {\n\t\t\t\treturn fmt.Errorf(\"open batch file: %w\", err)\n\t\t\t}\n\t\t\tdefer f.Close()\n\t\t\treader = f\n\t\t} else {\n\t\t\treader = cmd.InOrStdin()\n\t\t}\n","sourceCodeStart":82,"sourceCodeEnd":118,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/cmd/bd/batch.go#L82-L118","documentation":"The batch command requires a database handle to apply its operations. When the command is not being served by the proxied server (usesProxiedServer() is false) and the local store handle is nil, there is no database connection, so the command fails with this error plus a diagnostic hint. It prevents silently batching against nothing.","triggerScenarios":"Running 'bd batch' (with --file or stdin) in a context where the local store failed to open or was never initialized, and no proxied server is in use — store == nil.","commonSituations":"Running batch before 'bd init'; running outside a beads workspace; the database failed to open (corrupt .beads, locked Dolt) so store is nil; server/proxy mode expected but not active.","solutions":["Run 'bd init' in the project root to create the database","Start the bd server/proxy if you expect server mode, or unset server config to use direct mode","Check the diagHint() suffix in the message — it points at the concrete connection problem","Verify you are in the correct directory containing .beads"],"exampleFix":"// before\nbd batch --file ops.txt   # no DB\n// after\nbd init\nbd batch --file ops.txt","handlingStrategy":"validation","validationCode":"if _, err := os.Stat(\".beads\"); os.IsNotExist(err) {\n\treturn fmt.Errorf(\"no beads database here; run 'bd init' first\")\n}","typeGuard":"store != nil || usesProxiedServer()","tryCatchPattern":"if err := runBatch(ctx, store, ...); err != nil {\n\tif strings.Contains(err.Error(), \"no database connection\") {\n\t\t// bd init or start bd server, then retry\n\t}\n\treturn err\n}","preventionTips":["Run 'bd init' before batch operations in any new workspace","Confirm server/proxy mode is actually active if you expect proxied access","Check the diagHint appended to the message for the concrete connection cause","Wrap batch entry points with an existence check for the .beads directory"],"tags":["batch","database","connection","go"],"backgroundTag":"no-database-connection","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}