gastownhall/beads · error

%s: %w

Error message

%s: %w

What it means

ScanLabelWhitespace checks each label table for label values with leading/trailing whitespace; before querying it calls labelTableExists, and if that existence check errors the failure is wrapped as "<table>: <cause>". It means the scan could not even determine whether a label table exists — a database-level problem, not whitespace anomalies.

Source

Thrown at cmd/bd/doctor/fix/label_whitespace.go:95

// Total returns the number of flagged rows across all three classes.
func (a LabelWhitespaceAnomalies) Total() int {
	return len(a.Untrimmed) + len(a.Blank) + len(a.Internal)
}

// ScanLabelWhitespace reports labels carrying whitespace damage in both label
// tables. Tables absent from the schema are skipped; only tables with anomalies
// appear in the result.
//
// Classification happens in Go rather than SQL so that tabs, newlines and
// Unicode spaces are caught the same way strings.TrimSpace catches them —
// a TRIM()-based predicate would silently miss them.
func ScanLabelWhitespace(ctx context.Context, db *sql.DB) ([]LabelWhitespaceAnomalies, error) {
	var out []LabelWhitespaceAnomalies
	for _, table := range labelTables {
		exists, err := labelTableExists(ctx, db, table)
		if err != nil {
			return nil, fmt.Errorf("%s: %w", table, err)
		}
		if !exists {
			continue
		}

		a := LabelWhitespaceAnomalies{Table: table}
		//nolint:gosec // G201: table is a hardcoded constant, never user input.
		rows, err := db.QueryContext(ctx, fmt.Sprintf(`SELECT issue_id, label FROM %s`, table))
		if err != nil {
			return nil, fmt.Errorf("%s: %w", table, err)
		}
		for rows.Next() {
			var issueID string
			var label sql.NullString
			if err := rows.Scan(&issueID, &label); err != nil {
				_ = rows.Close()
				return nil, fmt.Errorf("%s: %w", table, err)
			}

View on GitHub (pinned to 71377f2769)

Solutions

  1. Verify database connectivity and server health, then re-run the label whitespace fix
  2. Grant the DB user permission to read table metadata (information_schema)
  3. Check Dolt server logs for the underlying metadata query error

Example fix

// before
anomalies, err := fix.ScanLabelWhitespace(ctx, db) // labels: driver: bad connection
// after: preflight the connection
if err := db.PingContext(ctx); err != nil {
	return fmt.Errorf("database unreachable: %w", err)
}
anomalies, err := fix.ScanLabelWhitespace(ctx, db)
Defensive patterns

Strategy: try-catch

Validate before calling

if err := db.PingContext(ctx); err != nil {
	return fmt.Errorf("DB unreachable before label whitespace scan: %w", err)
}
// Confirm metadata access works
if _, err := db.QueryContext(ctx, `SHOW TABLES`); err != nil {
	return fmt.Errorf("cannot read table metadata: %w", err)
}

Try / catch

anomalies, err := fix.ScanLabelWhitespace(ctx, db)
if err != nil {
	return fmt.Errorf("label whitespace scan aborted (no changes made): %w", err)
}

Prevention

When it happens

Trigger: Calling ScanLabelWhitespace when labelTableExists fails for a table: the schema-introspection query errors due to dropped connection, insufficient privileges to read information_schema/metadata, or driver errors against the Dolt server.

Common situations: Dolt server unreachable or restarted during `bd doctor`; DB user lacking permission to list tables; corrupted metadata after a failed migration.

Related errors


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