gastownhall/beads · error

db: AddRemote %s: %w

Error message

db: AddRemote %s: %w

What it means

This error is returned by AddRemote when the underlying version-control layer (r.vc.Remote with the 'add' subcommand) fails to register a new remote. It wraps the VC/Dolt error with the remote name for context. It means the remote was not created in dolt_remotes.

Source

Thrown at internal/storage/domain/db/remote.go:26

)

func NewRemoteSQLRepository(runner Runner) domain.RemoteSQLRepository {
	return &remoteSQLRepositoryImpl{
		runner: runner,
		vc:     NewDoltVersionControlSQLRepository(runner),
	}
}

type remoteSQLRepositoryImpl struct {
	runner Runner
	vc     DoltVersionControlSQLRepository
}

var _ domain.RemoteSQLRepository = (*remoteSQLRepositoryImpl)(nil)

func (r *remoteSQLRepositoryImpl) AddRemote(ctx context.Context, name, url string) error {
	if err := r.vc.Remote(ctx, "add", name, url); err != nil {
		return fmt.Errorf("db: AddRemote %s: %w", name, err)
	}
	return nil
}

func (r *remoteSQLRepositoryImpl) RemoveRemote(ctx context.Context, name string) error {
	if err := r.vc.Remote(ctx, "remove", name); err != nil {
		return fmt.Errorf("db: RemoveRemote %s: %w", name, err)
	}
	return nil
}

func (r *remoteSQLRepositoryImpl) ListRemotes(ctx context.Context) ([]domain.Remote, error) {
	rows, err := r.runner.QueryContext(ctx, "SELECT name, url FROM dolt_remotes")
	if err != nil {
		return nil, fmt.Errorf("db: ListRemotes: query: %w", err)
	}
	defer rows.Close()

View on GitHub (pinned to 71377f2769)

Solutions

  1. Read the wrapped cause after the remote name to see why `remote add` failed
  2. Verify the remote name is unique (run ListRemotes or `dolt remotes`) and the URL is valid for Dolt
  3. Ensure the database/repository is initialized before adding remotes
  4. If the remote already exists, remove it first (RemoveRemote) or reuse the existing entry

Example fix

// before
err := remotes.AddRemote(ctx, "origin", "gs://bucket/db") // fails: name exists
// after
existing, _ := remotes.ListRemotes(ctx)
if !containsRemote(existing, "origin") {
    err := remotes.AddRemote(ctx, "origin", "gs://bucket/db")
}
Defensive patterns

Strategy: validation

Validate before calling

remotes, err := store.ListRemotes(ctx)
if err != nil { return err }
for _, r := range remotes {
    if r.Name == name { return fmt.Errorf("remote %q already exists", name) }
}
if !strings.Contains(url, "://") { return fmt.Errorf("invalid remote url %q", url) }

Type guard

func isValidRemoteURL(url string) bool {
    return strings.HasPrefix(url, "aws://") || strings.HasPrefix(url, "gs://") || strings.HasPrefix(url, "file://") || strings.Contains(url, ".dolt")
}

Prevention

When it happens

Trigger: Calling AddRemote(ctx, name, url) where the underlying `dolt remote add` fails: invalid remote URL, remote name already exists, repository not initialized, or the storage backend rejects the operation.

Common situations: Typo in the remote URL scheme (not a valid Dolt/S3/file URL); adding a remote whose name already exists; calling sync setup before the database was initialized; running against a read-only or misconfigured Dolt data directory.

Related errors


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