gastownhall/beads · error

get dependency counts (dependents from %s): %w

Error message

get dependency counts (dependents from %s): %w

What it means

Returned by GetDependencyCountsInTx when the 'dependents' aggregate query (SELECT depends_on_id, COUNT(*) FROM <depTable> WHERE depends_on_id IN (...) AND type='blocks' GROUP BY depends_on_id) fails at QueryContext time and the failure is not a tolerated missing optional table. The %s names which dependency table (dependencies or wisp_dependencies) failed; %w wraps the driver error (syntax, connection, permissions, etc.).

Source

Thrown at internal/storage/issueops/dependency_queries.go:503

				}
			}
			_ = depRows.Close()
			if err := depRows.Err(); err != nil {
				return nil, fmt.Errorf("get dependency counts: blocker rows: %w", err)
			}

			//nolint:gosec // G201: depTable is hardcoded and inClause contains only ? placeholders.
			blockingRows, err := tx.QueryContext(ctx, fmt.Sprintf(`
				SELECT %s AS depends_on_id, COUNT(*) as cnt
				FROM %s
				WHERE %s AND type = 'blocks'
				GROUP BY %s
			`, DepTargetExpr, depTable, depTargetIn("", inClause), DepTargetExpr), args...)
			if err != nil {
				if optionalBlockedTable(depTable) && isTableNotExistError(err) {
					continue
				}
				return nil, fmt.Errorf("get dependency counts (dependents from %s): %w", depTable, err)
			}
			for blockingRows.Next() {
				var id string
				var cnt int
				if err := blockingRows.Scan(&id, &cnt); err != nil {
					_ = blockingRows.Close()
					return nil, fmt.Errorf("get dependency counts: scan dependent: %w", err)
				}
				if c, ok := result[id]; ok {
					c.DependentCount += cnt
				}
			}
			_ = blockingRows.Close()
			if err := blockingRows.Err(); err != nil {
				return nil, fmt.Errorf("get dependency counts: dependent rows: %w", err)
			}
		}
	}

View on GitHub (pinned to 71377f2769)

Solutions

  1. Inspect the wrapped driver error to identify whether it is no-such-table, permission denied, or connection failure.
  2. If the table is missing, initialize/migrate the database (bd init / schema migration) so the dependencies table exists.
  3. If permission denied, grant SELECT on dependencies/wisp_dependencies to the DB user.
  4. If it is a connection error, verify the remote Dolt server is reachable and the connection string is correct.
  5. Check client/server version compatibility if the SQL dialect is rejected.

Example fix

// before: DB user without SELECT grants
CREATE USER 'bd'@'%' IDENTIFIED BY '...';

// after: grant required read access
GRANT SELECT ON beads.* TO 'bd'@'%';
FLUSH PRIVILEGES;
Defensive patterns

Strategy: validation

Validate before calling

// Go: ensure required tables exist before calling
var n int
if err := tx.QueryRowContext(ctx,
    "SELECT COUNT(*) FROM information_schema.TABLES WHERE TABLE_NAME IN ('dependencies','issues')").Scan(&n); err != nil {
    return err
}
if n < 2 {
    return fmt.Errorf("required tables missing; run bd migrate")
}

Type guard

func isMissingTable(err error) bool {
    return err != nil && (strings.Contains(err.Error(), "no such table") ||
        strings.Contains(err.Error(), "doesn't exist"))
}

Try / catch

counts, err := GetDependencyCountsInTx(ctx, tx, ids)
if err != nil && strings.Contains(err.Error(), "dependents from dependencies") {
    if isMissingTable(errors.Unwrap(err)) {
        return fmt.Errorf("database not initialized: run bd migrate")
    }
    return err
}

Prevention

When it happens

Trigger: Calling GetDependencyCountsInTx when the dependencies table is missing entirely (fresh/corrupt DB — the optional-table skip only applies to wisp_dependencies), the SQL text fails to compile against the backend, the connection is broken, or the user lacks SELECT permission on the table.

Common situations: Database created before the dependencies table existed and never migrated; restricted DB user without SELECT grants; incompatible Dolt server rejecting the query dialect; corrupted database file.

Understand the failure class

Background: "query failed", "%w: SQL error" — wrapped database query errors in Go libraries explained — this error's family across 3 libraries.

Related errors


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