gastownhall/beads · error

failed to check remote %s: %w

Error message

failed to check remote %s: %w

What it means

HasRemote checks dolt_remotes for a named remote via a parameterized COUNT(*) query. This error wraps a failure of that query/scan — not 'remote not found' (that returns false, nil), but an actual failure executing or reading the result. Most commonly the dolt_remotes system table is unreadable because the database isn't a valid Dolt database or the query/scan failed for connection or context reasons.

Source

Thrown at internal/storage/dolt/store.go:4988

type CommitInfo = storage.CommitInfo

// HistoryEntry represents a row from dolt_history_* table
type HistoryEntry struct {
	CommitHash string
	Committer  string
	CommitDate time.Time
	// Issue data at that commit
	IssueData map[string]interface{}
}

// HasRemote checks if a Dolt remote with the given name exists.
func (s *DoltStore) HasRemote(ctx context.Context, name string) (bool, error) {
	var count int
	err := s.queryRowContext(ctx, func(row *sql.Row) error {
		return row.Scan(&count)
	}, "SELECT COUNT(*) FROM dolt_remotes WHERE name = ?", name)
	if err != nil {
		return false, fmt.Errorf("failed to check remote %s: %w", name, err)
	}
	return count > 0, nil
}

// AddRemote adds a Dolt remote
func (s *DoltStore) AddRemote(ctx context.Context, name, url string) error {
	_, err := s.db.ExecContext(ctx, "CALL DOLT_REMOTE('add', ?, ?)", name, url)
	if err != nil {
		return fmt.Errorf("failed to add remote %s: %w", name, err)
	}
	return nil
}

// Status returns the current Dolt status (staged/unstaged changes)
func (s *DoltStore) Status(ctx context.Context) (*DoltStatus, error) {
	return versioncontrolops.Status(ctx, s.db)
}

View on GitHub (pinned to 71377f2769)

Solutions

  1. Verify the database is a Dolt database (.dolt directory present, dolt sql-server running).
  2. Run the query manually (SELECT COUNT(*) FROM dolt_remotes WHERE name='<name>') to see the underlying error.
  3. Check ctx deadline and connection health (db.Ping).
  4. Retry — transient connection errors resolve after pool recycling.
  5. If remotes were manipulated externally, verify dolt_remotes integrity (dolt remotes list).

Example fix

// before
has, err := store.HasRemote(ctx, "origin") // ctx from an already-timed-out request
// after
qctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
has, err := store.HasRemote(qctx, "origin")
Defensive patterns

Strategy: validation

Validate before calling

func validateDoltDB(db *sql.DB, ctx context.Context) error {
    var name string
    return db.QueryRowContext(ctx, "SELECT DATABASE()").Scan(&name) // fails fast if not a Dolt db/session
}
// also: file .dolt directory exists before opening the store

Try / catch

has, err := store.HasRemote(ctx, "origin")
if err != nil {
    var drivenErr error
    if errors.As(err, &drivenErr) && strings.Contains(err.Error(), "dolt_remotes") {
        return fmt.Errorf("not a Dolt database or dolt_remotes unreadable: %w", err)
    }
    return err
}

Prevention

When it happens

Trigger: Calling HasRemote(ctx, name) when queryRowContext's row.Scan fails: ctx cancelled mid-query, Dolt server unavailable, session error reading dolt_remotes, or a scan type mismatch.

Common situations: Running against a non-Dolt database or corrupted .dolt directory; server down; checking remotes with an expired request context inside a longer operation.

Related errors


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