{"record":{"id":"990576a1c1c6d893","repo":"gastownhall/beads","slug":"check-s-exists-w","errorCode":null,"errorMessage":"check %s exists: %w","messagePattern":"check (.+?) exists: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/bd/doctor/fix/clone_local_fks.go","lineNumber":77,"sourceCode":"\n\tdb, _, err := openDoltDB(beadsDir)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tdefer db.Close()\n\n\treturn scanSeveredCloneLocalFKs(db)\n}\n\nfunc scanSeveredCloneLocalFKs(db *sql.DB) ([]SeveredCloneLocalFK, error) {\n\tvar severed []SeveredCloneLocalFK\n\tfor _, fk := range CloneLocalFKs {\n\t\tvar tables int\n\t\tif err := db.QueryRow(\n\t\t\t`SELECT COUNT(*) FROM information_schema.TABLES WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = ?`,\n\t\t\tfk.Table,\n\t\t).Scan(&tables); err != nil {\n\t\t\treturn nil, fmt.Errorf(\"check %s exists: %w\", fk.Table, err)\n\t\t}\n\t\tif tables == 0 {\n\t\t\tcontinue\n\t\t}\n\n\t\tvar constraints int\n\t\tif err := db.QueryRow(\n\t\t\t`SELECT COUNT(*) FROM information_schema.TABLE_CONSTRAINTS\n\t\t\t WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = ? AND CONSTRAINT_NAME = ? AND CONSTRAINT_TYPE = 'FOREIGN KEY'`,\n\t\t\tfk.Table, fk.Constraint,\n\t\t).Scan(&constraints); err != nil {\n\t\t\treturn nil, fmt.Errorf(\"check %s.%s: %w\", fk.Table, fk.Constraint, err)\n\t\t}\n\t\tif constraints > 0 {\n\t\t\tcontinue\n\t\t}\n\n\t\tvar orphans int","sourceCodeStart":59,"sourceCodeEnd":95,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/cmd/bd/doctor/fix/clone_local_fks.go#L59-L95","documentation":"scanSeveredCloneLocalFKs probes information_schema.TABLES to confirm each table in the fixed CloneLocalFKs spec still exists before checking its foreign key. If the COUNT(*) query itself fails (the table merely being absent is handled by `continue`), the scan aborts with this wrapped error.","triggerScenarios":"db.QueryRow on information_schema.TABLES returns an error inside scanSeveredCloneLocalFKs (cmd/bd/doctor/fix/clone_local_fks.go:77) — database connectivity loss, permission denial on information_schema, or driver/storage failure during CloneLocalFKEnforcement or ScanSeveredCloneLocalFKs.","commonSituations":"Dolt server restarted mid-scan, corrupted .beads database, or running doctor against a workspace where the database driver rejects information_schema queries.","solutions":["Check the wrapped driver error (%w) — most often a connection or storage problem — and re-run `bd doctor` once the DB is reachable.","Confirm the .beads Dolt database is not locked or corrupted; restart the Dolt-backed store if needed.","Verify the database user has SELECT on information_schema.","Update bd if the bundled driver version has known information_schema incompatibilities."],"exampleFix":null,"handlingStrategy":"retry","validationCode":"var n int\nif err := db.Ping(); err != nil {\n\t// database unreachable; fix connectivity before scanning\n\treturn err\n}","typeGuard":null,"tryCatchPattern":"severed, err := ScanSeveredCloneLocalFKs(ctx, db)\nif err != nil && strings.Contains(err.Error(), \"check \") {\n\t// DB-level failure: reconnect/backoff then rescan\n\treturn fmt.Errorf(\"rescan after fixing DB: %w\", err)\n}","preventionTips":["Keep the Dolt-backed store healthy and reachable before running doctor","Ensure the DB user can read information_schema","Avoid running doctor concurrently with other bd writes","Keep bd and its driver versions in sync"],"tags":["dolt","doctor","foreign-keys","information-schema"],"backgroundTag":"database-query-failed","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}