{"record":{"id":"68c6459bdecf376b","repo":"gastownhall/beads","slug":"failed-to-load-config-w-68c645","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/config_values.go","lineNumber":20,"sourceCode":"\nimport (\n\t\"fmt\"\n\t\"strings\"\n\n\t\"github.com/steveyegge/beads/internal/configfile\"\n)\n\n// ConfigValues fixes invalid configuration values in metadata.json.\n// Currently handles: database field pointing to SQLite name when backend is Dolt.\nfunc ConfigValues(path string) error {\n\tbeadsDir, err := resolvedWorkspaceBeadsDir(path)\n\tif err != nil {\n\t\treturn err\n\t}\n\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\treturn fmt.Errorf(\"no metadata.json found\")\n\t}\n\n\tfixed := false\n\n\t// Fix database field: when backend is Dolt, database should be \"dolt\" not \"beads.db\"\n\tif cfg.GetBackend() == configfile.BackendDolt {\n\t\tif strings.HasSuffix(cfg.Database, \".db\") || strings.HasSuffix(cfg.Database, \".sqlite\") || strings.HasSuffix(cfg.Database, \".sqlite3\") {\n\t\t\tfmt.Printf(\"  Updating database: %q → %q (Dolt backend uses directory)\\n\", cfg.Database, \"dolt\")\n\t\t\tcfg.Database = \"dolt\"\n\t\t\tfixed = true\n\t\t}\n\t}\n\n\tif !fixed {\n\t\tfmt.Println(\"  → No configuration issues to fix\")","sourceCodeStart":2,"sourceCodeEnd":38,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/cmd/bd/doctor/fix/config_values.go#L2-L38","documentation":"ConfigValues (cmd/bd/doctor/fix/config_values.go) wraps errors from configfile.Load(beadsDir) with this message. Load fails when .beads/metadata.json exists but is unreadable or unparseable (bad JSON, permissions, I/O error) — distinct from the missing-file case, which returns nil cfg and the \"no metadata.json found\" error.","triggerScenarios":"configfile.Load returns a non-nil error: malformed JSON in .beads/metadata.json, file permissions deny read, disk I/O error, or the beadsDir resolution produced a path Load cannot read.","commonSituations":"A partially written or hand-edited metadata.json with a syntax error; running bd as a different user than the one who created the workspace; a .beads/redirect pointing at a directory that is unreadable or on a failed mount.","solutions":["Inspect .beads/metadata.json for JSON syntax errors (run it through jq or a JSON linter) and fix or restore it","Fix file permissions: ensure the current user can read .beads/metadata.json (e.g. chmod 644)","Follow any .beads/redirect to confirm the target beads dir exists and is readable","If the file is corrupted and unrecoverable, re-initialize the workspace metadata (bd init) and reapply settings"],"exampleFix":"// before (invalid JSON)\n{ \"backend\": \"dolt\", \"database\": \"dolt\", }\n// after\n{ \"backend\": \"dolt\", \"database\": \"dolt\" }","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":"cfg, err := configfile.Load(beadsDir)\nif err != nil {\n    return fmt.Errorf(\"failed to load config: %w\", err) // surface JSON/permission detail to user\n}","preventionTips":["Validate metadata.json with a JSON parser after hand edits","Keep consistent user ownership of .beads across sudo/non-sudo runs","Write metadata.json atomically (temp file + rename) in tooling","Back up metadata.json before migrations"],"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"}