gastownhall/beads · error

invalid remote name: %w

Error message

invalid remote name: %w

What it means

AddCLIRemote validates the remote name with remotecache.ValidateRemoteName before invoking 'dolt remote add'. This error wraps that validation failure, so the name never reaches the CLI. It prevents invalid names from creating broken remote configuration.

Source

Thrown at internal/storage/doltutil/remotes.go:159

}

// RemoteURLsMatch compares remote URLs after Dolt-compatible normalization.
func RemoteURLsMatch(got, want string) bool {
	if got == "" || want == "" {
		return got == want
	}
	if got == want || doltremote.Normalize(got) == doltremote.Normalize(want) {
		return true
	}
	return false
}

// AddCLIRemote adds a remote at the filesystem level via dolt CLI.
// Remote mutation should normally go through SQL; this is reserved for the
// local CLI mirror required by subprocess push/pull/fetch routing.
func AddCLIRemote(dbPath, name, url string) error {
	if err := remotecache.ValidateRemoteName(name); err != nil {
		return fmt.Errorf("invalid remote name: %w", err)
	}
	if err := remotecache.ValidateRemoteURL(url); err != nil {
		return fmt.Errorf("invalid remote URL: %w", err)
	}
	cmd := exec.Command("dolt", "remote", "add", name, url) // #nosec G204 -- validated argv
	cmd.Dir = dbPath
	out, err := cmd.CombinedOutput()
	if err != nil {
		return fmt.Errorf("dolt remote add failed: %s: %w", strings.TrimSpace(string(out)), err)
	}
	return nil
}

// RemoveCLIRemote removes a remote at the filesystem level via dolt CLI.
func RemoveCLIRemote(dbPath, name string) error {
	if err := remotecache.ValidateRemoteName(name); err != nil {
		return fmt.Errorf("invalid remote name: %w", err)
	}

View on GitHub (pinned to 71377f2769)

Solutions

  1. Sanitize the remote name: trim spaces, strip invalid characters, lowercase, remove path separators.
  2. Follow Dolt naming rules (alphanumeric, dash, underscore, dot; no leading dashes).
  3. Apply the same validation (remotecache.ValidateRemoteName) before calling AddCLIRemote.
  4. Log the offending name so users can correct their config.

Example fix

// before
name := strings.TrimSpace(userInput) // may contain spaces/slashes
_ = doltutil.AddCLIRemote(dbPath, name, url)
// after
name := sanitizeRemoteName(userInput)
if err := remotecache.ValidateRemoteName(name); err != nil {
    return fmt.Errorf("rejecting remote name %q: %w", name, err)
}
_ = doltutil.AddCLIRemote(dbPath, name, url)
Defensive patterns

Strategy: validation

Validate before calling

var remoteNameRe = regexp.MustCompile(`^[A-Za-z0-9][A-Za-z0-9._-]*$`)
if !remoteNameRe.MatchString(name) { return fmt.Errorf("invalid remote name: %q", name) }

Try / catch

if err := doltutil.AddCLIRemote(dbPath, name, url); err != nil {
    if strings.Contains(err.Error(), "invalid remote name") {
        return fmt.Errorf("fix remote name %q: %w", name, err)
    }
    return err
}

Prevention

When it happens

Trigger: Calling AddCLIRemote/EnsureCLIRemote with a name containing illegal characters, empty string, whitespace, path separators, or reserved/overlong names.

Common situations: Constructing remote names from user input or hostnames without sanitizing; template/config typos; slashes from URL fragments leaking into the name.

Related errors


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