gastownhall/beads · warning

invalid peer name: %w

Error message

invalid peer name: %w

What it means

AddFederationPeerInTx validates the peer's Name field via ValidatePeerName before inserting, and wraps any validation failure with "invalid peer name". This is a pure input-validation error: the peer record was rejected before touching the database. Fix the peer name in your FederationPeer struct and retry.

Source

Thrown at internal/storage/issueops/federation.go:34

// ValidatePeerName checks that a peer name is safe for use as a Dolt remote name.
func ValidatePeerName(name string) error {
	if name == "" {
		return fmt.Errorf("peer name cannot be empty")
	}
	if len(name) > 64 {
		return fmt.Errorf("peer name too long (max 64 characters)")
	}
	if !validPeerNameRegex.MatchString(name) {
		return fmt.Errorf("peer name must start with a letter and contain only alphanumeric characters, hyphens, and underscores")
	}
	return nil
}

// AddFederationPeerInTx upserts a federation peer record. The encryptedPwd
// should already be encrypted by the caller; pass nil for no password.
func AddFederationPeerInTx(ctx context.Context, tx *sql.Tx, peer *storage.FederationPeer, encryptedPwd []byte) error {
	if err := ValidatePeerName(peer.Name); err != nil {
		return fmt.Errorf("invalid peer name: %w", err)
	}

	_, err := tx.ExecContext(ctx, `
		INSERT INTO federation_peers (name, remote_url, username, password_encrypted, sovereignty)
		VALUES (?, ?, ?, ?, ?)
		ON DUPLICATE KEY UPDATE
			remote_url = VALUES(remote_url),
			username = VALUES(username),
			password_encrypted = VALUES(password_encrypted),
			sovereignty = VALUES(sovereignty),
			updated_at = CURRENT_TIMESTAMP
	`, peer.Name, peer.RemoteURL, peer.Username, encryptedPwd, peer.Sovereignty)

	if err != nil {
		return fmt.Errorf("add federation peer: %w", err)
	}
	return nil
}

View on GitHub (pinned to 71377f2769)

Solutions

  1. Validate the peer name with issueops.ValidatePeerName(peer.Name) before calling AddFederationPeerInTx and show the underlying reason to the user
  2. Inspect the wrapped error (%w) for the specific rule violated (empty, invalid characters, too long) and correct peer.Name
  3. If names come from user input or config, trim and normalize them at load time

Example fix

// before
peer := &storage.FederationPeer{Name: cfg.PeerName} // may be "" or "my peer"
err := issueops.AddFederationPeerInTx(ctx, tx, peer, nil)
// after
name := strings.TrimSpace(cfg.PeerName)
if err := issueops.ValidatePeerName(name); err != nil {
    return fmt.Errorf("bad --peer-name: %w", err)
}
peer := &storage.FederationPeer{Name: name}
err := issueops.AddFederationPeerInTx(ctx, tx, peer, nil)
Defensive patterns

Strategy: validation

Validate before calling

if err := issueops.ValidatePeerName(peer.Name); err != nil {
    return fmt.Errorf("peer name %q invalid: %w", peer.Name, err)
}

Prevention

When it happens

Trigger: Calling AddFederationPeerInTx with a FederationPeer whose Name is empty, contains whitespace/illegal characters, or otherwise fails ValidatePeerName.

Common situations: Constructing a FederationPeer from unparsed config, CLI flags, or YAML where the name field was left blank or contains spaces; syncing peer metadata from another instance with legacy names.

Related errors


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