{"record":{"id":"4034e4cea82102d2","repo":"gastownhall/beads","slug":"no-metadata-json-found-4034e4","errorCode":null,"errorMessage":"no metadata.json found","messagePattern":"no metadata\\.json found","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/bd/doctor/fix/database_config.go","lineNumber":28,"sourceCode":"\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\n\t\tfixed = true\n\t}\n\n\tif !fixed {","sourceCodeStart":10,"sourceCodeEnd":46,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/cmd/bd/doctor/fix/database_config.go#L10-L46","documentation":"DatabaseConfig errors when .beads/metadata.json does not exist (configfile.Load returns nil, nil). The DatabaseConfig fix reconciles the configured database name against local .db files, so it cannot run in a workspace without metadata.","triggerScenarios":"Invoking DatabaseConfig in a directory whose resolved .beads dir lacks metadata.json: bd never initialized there, wrong working directory, or .beads/redirect pointing at an empty/stale location.","commonSituations":"Running doctor fixes in a brand-new clone before `bd init`; pointing bd at a repo without beads metadata; a moved workspace whose redirect is stale.","solutions":["Run `bd init` in the project root to create .beads/metadata.json","Confirm you are in the intended repository (ls .beads/ should show metadata.json)","Check and fix .beads/redirect if it points to a nonexistent directory","Restore metadata.json from git history or a backup if it was accidentally removed"],"exampleFix":"// shell\n$ ls .beads/metadata.json   # not found\n$ bd init\n$ bd doctor fix","handlingStrategy":"validation","validationCode":"if _, err := os.Stat(filepath.Join(beadsDir, \"metadata.json\")); os.IsNotExist(err) {\n    return fmt.Errorf(\"workspace not initialized: run 'bd init'\")\n}","typeGuard":"func hasMetadata(beadsDir string) bool {\n    _, err := os.Stat(filepath.Join(beadsDir, \"metadata.json\"))\n    return err == nil\n}","tryCatchPattern":"if err := fix.DatabaseConfig(path); err != nil {\n    if err.Error() == \"no metadata.json found\" {\n        // initialize workspace or correct the path\n    }\n    return err\n}","preventionTips":["Run `bd init` in new clones before doctor fixes","Verify cwd is the correct repository","Fix stale .beads/redirect entries after moving workspaces"],"tags":["go","config","missing-file"],"backgroundTag":"missing-metadata-json","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}