{"record":{"id":"79eef905ac2b741c","repo":"gastownhall/beads","slug":"failed-to-load-config-w-79eef9","errorCode":null,"errorMessage":"failed to load config: %w","messagePattern":"failed to load config: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/bd/doctor/fix/database_config.go","lineNumber":24,"sourceCode":"\t\"strings\"\n\n\t\"github.com/steveyegge/beads/internal/configfile\"\n)\n\n// DatabaseConfig auto-detects and fixes metadata.json database config mismatches.\n// This fix only applies to SQLite backends where .db files on disk may not match\n// the configured database name. Dolt backends store data on a server, so there\n// are no local .db files to reconcile.\nfunc DatabaseConfig(path string) error {\n\tbeadsDir, err := resolvedWorkspaceBeadsDir(path)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\t// Load existing config\n\tcfg, err := configfile.Load(beadsDir)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to load config: %w\", err)\n\t}\n\tif cfg == nil {\n\t\t// No config exists - nothing to fix\n\t\treturn fmt.Errorf(\"no metadata.json found\")\n\t}\n\n\t// Dolt backend stores data on the server — no local .db files to reconcile\n\tif cfg.GetBackend() == configfile.BackendDolt {\n\t\treturn fmt.Errorf(\"database config fix not applicable for Dolt backend (data is on the server)\")\n\t}\n\n\tfixed := false\n\n\t// Check if configured database name matches the actual .db file on disk\n\tactualDB := findActualDBFile(beadsDir)\n\tif actualDB != \"\" && cfg.Database != actualDB {\n\t\tfmt.Printf(\"  Updating database: %s → %s\\n\", cfg.Database, actualDB)\n\t\tcfg.Database = actualDB","sourceCodeStart":6,"sourceCodeEnd":42,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/cmd/bd/doctor/fix/database_config.go#L6-L42","documentation":"DatabaseConfig (cmd/bd/doctor/fix/database_config.go) wraps errors from configfile.Load(beadsDir) with this message. Load fails when .beads/metadata.json exists but cannot be read or parsed (malformed JSON, permission denied, I/O error), as opposed to the missing-file case which yields the \"no metadata.json found\" error.","triggerScenarios":"configfile.Load returns a non-nil error during DatabaseConfig: invalid JSON in .beads/metadata.json, unreadable file permissions, or an unreadable resolved beads dir (possibly via .beads/redirect).","commonSituations":"Hand-edited or truncated metadata.json; running bd as a different user; redirect target on a failed/unmounted drive; corrupted metadata after an interrupted write.","solutions":["Validate .beads/metadata.json JSON syntax (jq . .beads/metadata.json) and repair or restore it","Fix read permissions on .beads/metadata.json and the .beads directory","Resolve the .beads/redirect target and confirm it exists and is readable","Re-run `bd init` to regenerate metadata if the file is unrecoverable, then reapply backend/database settings"],"exampleFix":"// before (truncated)\n{ \"backend\": \"sqlite\", \"data\n// after\n{ \"backend\": \"sqlite\", \"database\": \"beads.db\" }","handlingStrategy":"try-catch","validationCode":"data, err := os.ReadFile(filepath.Join(beadsDir, \"metadata.json\"))\nif err != nil { return err }\nvar probe map[string]any\nif err := json.Unmarshal(data, &probe); err != nil {\n    return fmt.Errorf(\"metadata.json is not valid JSON: %w\", err)\n}","typeGuard":"func metadataReadable(beadsDir string) bool {\n    fi, err := os.Stat(filepath.Join(beadsDir, \"metadata.json\"))\n    return err == nil && !fi.IsDir() && fi.Mode().Perm()&0o400 != 0\n}","tryCatchPattern":"if err := fix.DatabaseConfig(path); err != nil {\n    if strings.HasPrefix(err.Error(), \"failed to load config\") {\n        // inspect metadata.json JSON validity and permissions\n    }\n    return err\n}","preventionTips":["Lint metadata.json after manual edits","Keep .beads ownership consistent across users","Resolve redirect targets before running database fixes","Regenerate metadata via `bd init` if it is corrupted"],"tags":["go","config","json"],"backgroundTag":"config-load-failed","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}