hashicorp/nomad · error

cannot give both an address and id

Error message

cannot give both an address and id

What it means

The `nomad operator raft transfer-leadership` command requires exactly one destination peer selector. raftTransferLeadership validates that the user supplied either a peer address (-peer-address) or a peer id (-peer-id), and rejects the case where both flags are provided, because the target would be ambiguous.

Source

Thrown at command/operator_raft_leadership_transfer.go:110

	if err := raftTransferLeadership(peerAddress, peerID, operator); err != nil {
		c.Ui.Error(fmt.Sprintf("Error transferring leadership to peer: %v", err))
		return 1
	}
	if peerAddress != "" {
		c.Ui.Output(fmt.Sprintf("Transferred leadership to peer with address %q", peerAddress))
	} else {
		c.Ui.Output(fmt.Sprintf("Transferred leadership to peer with id %q", peerID))
	}

	return 0
}

func raftTransferLeadership(address, id string, operator *api.Operator) error {
	if len(address) == 0 && len(id) == 0 {
		return fmt.Errorf("an address or id is required for the destination peer")
	}
	if len(address) > 0 && len(id) > 0 {
		return fmt.Errorf("cannot give both an address and id")
	}

	// Try to perform the leadership transfer.
	if len(address) > 0 {
		if err := operator.RaftTransferLeadershipByAddress(address, nil); err != nil {
			return err
		}
	} else {
		if err := operator.RaftTransferLeadershipByID(id, nil); err != nil {
			return err
		}
	}

	return nil
}

View on GitHub (pinned to 482b49bf1a)

Solutions

  1. Remove one of the two flags — pass only -peer-address or only -peer-id.
  2. Use -peer-id when you have the Raft ID from `nomad operator raft list-peers`; use -peer-address (host:port) otherwise.
  3. If flags come from a script/template, ensure only one is populated and the other is empty/omitted.

Example fix

// before
nomad operator raft transfer-leadership -peer-address 127.0.0.1:4647 -peer-id 2b7f0a42-5f60

// after
nomad operator raft transfer-leadership -peer-id 2b7f0a42-5f60
Defensive patterns

Strategy: validation

Validate before calling

if (address !== '' && id !== '') throw new Error('pass either -peer-address or -peer-id, not both'); if (address === '' && id === '') throw new Error('one of -peer-address or -peer-id is required');

Prevention

When it happens

Trigger: Running the command with both -peer-address and -peer-id set to non-empty values in the same invocation; programmatically calling raftTransferLeadership with both address and id strings populated.

Common situations: Users copy an example command that uses -peer-address, then append -peer-id from `nomad operator raft list-peers` output thinking both are needed; scripts that build flags from config where both fields happen to be filled.

Understand the failure class

Background: "mutually exclusive" flag errors: what "can't supply both nx and xx", "--raw is not compatible with -i" and "cannot be used with" mean, and how to fix them — this error's family across 29 libraries.

Related errors


AI-assisted analysis of hashicorp/nomad@482b49bf1a (2026-09-04). Data as JSON: /api/errors/7242bcb9ab3e4a5f. Report an issue: GitHub.