gastownhall/beads · error

check %s exists: %w

Error message

check %s exists: %w

What it means

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.

Source

Thrown at cmd/bd/doctor/fix/clone_local_fks.go:77

	db, _, err := openDoltDB(beadsDir)
	if err != nil {
		return nil, err
	}
	defer db.Close()

	return scanSeveredCloneLocalFKs(db)
}

func scanSeveredCloneLocalFKs(db *sql.DB) ([]SeveredCloneLocalFK, error) {
	var severed []SeveredCloneLocalFK
	for _, fk := range CloneLocalFKs {
		var tables int
		if err := db.QueryRow(
			`SELECT COUNT(*) FROM information_schema.TABLES WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = ?`,
			fk.Table,
		).Scan(&tables); err != nil {
			return nil, fmt.Errorf("check %s exists: %w", fk.Table, err)
		}
		if tables == 0 {
			continue
		}

		var constraints int
		if err := db.QueryRow(
			`SELECT COUNT(*) FROM information_schema.TABLE_CONSTRAINTS
			 WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = ? AND CONSTRAINT_NAME = ? AND CONSTRAINT_TYPE = 'FOREIGN KEY'`,
			fk.Table, fk.Constraint,
		).Scan(&constraints); err != nil {
			return nil, fmt.Errorf("check %s.%s: %w", fk.Table, fk.Constraint, err)
		}
		if constraints > 0 {
			continue
		}

		var orphans int

View on GitHub (pinned to 71377f2769)

Solutions

  1. Check the wrapped driver error (%w) — most often a connection or storage problem — and re-run `bd doctor` once the DB is reachable.
  2. Confirm the .beads Dolt database is not locked or corrupted; restart the Dolt-backed store if needed.
  3. Verify the database user has SELECT on information_schema.
  4. Update bd if the bundled driver version has known information_schema incompatibilities.
Defensive patterns

Strategy: retry

Validate before calling

var n int
if err := db.Ping(); err != nil {
	// database unreachable; fix connectivity before scanning
	return err
}

Try / catch

severed, err := ScanSeveredCloneLocalFKs(ctx, db)
if err != nil && strings.Contains(err.Error(), "check ") {
	// DB-level failure: reconnect/backoff then rescan
	return fmt.Errorf("rescan after fixing DB: %w", err)
}

Prevention

When it happens

Trigger: 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.

Common situations: Dolt server restarted mid-scan, corrupted .beads database, or running doctor against a workspace where the database driver rejects information_schema queries.

Understand the failure class

Background: Database query failed: Internal Server Error 500s wrapping SQL, Prisma, and connection failures — what to check first — this error's family across 16 libraries.

Related errors


AI-assisted analysis of gastownhall/beads@71377f2769 (2026-08-30). Data as JSON: /api/errors/990576a1c1c6d893. Report an issue: GitHub.