{"record":{"id":"f22ace9915aef9d4","repo":"gastownhall/beads","slug":"no-database-available","errorCode":null,"errorMessage":"no database available","messagePattern":"no database available","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/bd/orphans.go","lineNumber":181,"sourceCode":"\t// may belong to a different project (GH#2469).\n\tif yamlPrefix := config.GetString(\"issue-prefix\"); yamlPrefix != \"\" {\n\t\treturn yamlPrefix\n\t}\n\tctx := context.Background()\n\tprefix, err := store.GetConfig(ctx, \"issue_prefix\")\n\tif err != nil || prefix == \"\" {\n\t\treturn \"bd\"\n\t}\n\treturn prefix\n}\n\n// getIssueProviderFn is the function used to create an IssueProvider.\n// It is a variable so tests can substitute a mock without needing a real store.\nvar getIssueProviderFn = func(labels, labelsAny []string) (types.IssueProvider, func(), error) {\n\tif store != nil {\n\t\treturn &doltStoreProvider{labels: labels, labelsAny: labelsAny}, func() {}, nil\n\t}\n\treturn nil, nil, fmt.Errorf(\"no database available\")\n}\n\n// getIssueProvider returns an IssueProvider backed by the global Dolt store.\n// labels and labelsAny are passed through to SearchIssues for label filtering.\nfunc getIssueProvider(labels, labelsAny []string) (types.IssueProvider, func(), error) {\n\treturn getIssueProviderFn(labels, labelsAny)\n}\n\n// findOrphanedIssues wraps the shared doctor package function and converts to output format.\n// It respects the --db flag for cross-repo orphan detection.\n// labels and labelsAny are passed to the issue provider to restrict which issues are considered.\nfunc findOrphanedIssues(path string, labels, labelsAny []string) ([]orphanIssueOutput, error) {\n\tprovider, cleanup, err := getIssueProvider(labels, labelsAny)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"unable to find orphaned issues: %w\", err)\n\t}\n\tdefer cleanup()\n","sourceCodeStart":163,"sourceCodeEnd":199,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/cmd/bd/orphans.go#L163-L199","documentation":"getIssueProviderFn creates an IssueProvider backed by the global Dolt store. If the global store variable is nil (no database open in this process), it returns 'no database available'. It is a guard so orphan-search callers never run without a backing store.","triggerScenarios":"Calling getIssueProvider (via findOrphanedIssues, bd orphans / bd doctor conventions orphans) when the global `store` is nil — e.g. no DB was opened, wrong --db path, or the store failed to initialize earlier.","commonSituations":"Running 'bd orphans' outside a beads repository (no .beads database), pointing --db at a nonexistent path, or invoking the command in a context where store initialization was skipped (proxied/server mode misconfiguration).","solutions":["Run the command from a directory with an initialized beads DB, or pass the correct --db path.","Initialize a database with 'bd init' if none exists.","Run 'bd doctor' to check store connectivity and initialization errors.","For proxied/server usage, ensure the server-side store is opened before handling orphan requests."],"exampleFix":"// before\nbd orphans                      # run outside repo -> no database available\n// after\ncd /path/to/repo && bd orphans  # or: bd orphans --db /path/to/.beads","handlingStrategy":"validation","validationCode":"if store == nil {\n    return errors.New(\"no database available; run bd init or pass --db\")\n}\nif _, err := os.Stat(filepath.Join(path, \".beads\")); err != nil {\n    return fmt.Errorf(\"not a beads repo: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"provider, cleanup, err := getIssueProvider(labels, labelsAny)\nif err != nil {\n    if strings.Contains(err.Error(), \"no database available\") {\n        // open/init the store, then retry\n    }\n    return err\n}\ndefer cleanup()","preventionTips":["Run orphan commands from a repo with an initialized beads DB","Pass --db explicitly when operating cross-repo","Run bd doctor to confirm store initialization","Fail fast in scripts if bd init has not been run"],"tags":["go","database","orphans","store"],"backgroundTag":"no-database-available","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}