{"record":{"id":"8362b2419221a533","repo":"gastownhall/beads","slug":"failed-to-scan-dependency-keys-w","errorCode":null,"errorMessage":"failed to scan dependency keys: %w","messagePattern":"failed to scan dependency keys: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/bd/doctor/fix/dep_keys.go","lineNumber":105,"sourceCode":"\t\tfmt.Printf(\"  Dependency key fix skipped (%v)\\n\", err)\n\t\treturn nil\n\t}\n\tdefer db.Close()\n\n\tif skip, err := guardFixTarget(\"Dependency key fix\", db, beadsDir, cfg); skip {\n\t\treturn err\n\t}\n\n\treturn repairDependencyKeys(context.Background(), db, verbose)\n}\n\n// repairDependencyKeys scans and repairs rekey-backfill leftovers on an open\n// connection. Split from DependencyKeys so the repair logic is testable\n// against an existing store handle.\nfunc repairDependencyKeys(ctx context.Context, db *sql.DB, verbose bool) error {\n\tanomalies, err := ScanDependencyKeys(ctx, db)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to scan dependency keys: %w\", err)\n\t}\n\tif len(anomalies) == 0 {\n\t\tfmt.Println(\"  No dependency key anomalies to fix\")\n\t\treturn nil\n\t}\n\n\t// Uses explicit transaction so writes persist when @@autocommit is OFF\n\t// (e.g. Dolt server started with --no-auto-commit).\n\ttx, err := db.Begin()\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to begin transaction: %w\", err)\n\t}\n\tvar rekeyed, removed, failed int\n\trepairedTables := make(map[string]bool)\n\tfor _, a := range anomalies {\n\t\tshowIndividual := verbose || len(a.MisKeyed)+len(a.NullTarget) < 20\n\t\tfor _, mk := range a.MisKeyed {\n\t\t\t//nolint:gosec // G201: table is a hardcoded constant, never user input.","sourceCodeStart":87,"sourceCodeEnd":123,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/cmd/bd/doctor/fix/dep_keys.go#L87-L123","documentation":"repairDependencyKeys first calls ScanDependencyKeys to find mis-keyed or null-target dependency rows; if that scan returns any error (connection failure, rows iteration error, table-existence check failure), it is wrapped as \"failed to scan dependency keys: %w\". This is the top-level signal that the repair aborted before making any changes — nothing was written.","triggerScenarios":"Running `bd doctor` dependency-keys fix (or the test) when ScanDependencyKeys returns an error: e.g. the dependency tables cannot be queried because the DB connection is down, a table query fails, or the rows cursor errors (see error 410).","commonSituations":"Dolt server not running or restarting during `bd doctor fix`; database migration incomplete so dependency tables are unreadable; permission errors on the database user.","solutions":["Verify the database is reachable (start/restart the Dolt server, check bd doctor database status)","Re-run the fix command once the connection is stable","If a specific table is failing, inspect that table's health directly and repair or restore it"],"exampleFix":"// before (broken connection)\nerr := repairDependencyKeys(ctx, db, verbose) // \"failed to scan dependency keys: ...\"\n// after (caller guards)\nif err := db.PingContext(ctx); err != nil {\n\treturn fmt.Errorf(\"database unreachable: %w\", err)\n}\nreturn repairDependencyKeys(ctx, db, verbose)","handlingStrategy":"try-catch","validationCode":"if err := db.PingContext(ctx); err != nil {\n\treturn fmt.Errorf(\"skipping dependency key repair, DB unreachable: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"if err := repairDependencyKeys(ctx, db, verbose); err != nil {\n\tif strings.HasPrefix(err.Error(), \"failed to scan dependency keys\") {\n\t\tlog.Printf(\"repair aborted before any writes (safe to retry): %v\", err)\n\t\treturn err\n\t}\n\treturn err\n}","preventionTips":["Verify database connectivity before running doctor fixes","Don't run repairs while the Dolt server is restarting or a migration is in flight","Use errors.Is/errors.As on the wrapped cause where possible to distinguish scan vs write failures"],"tags":["database","doctor","scan","dolt"],"backgroundTag":"doctor-repair-scan-failed","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}