{"record":{"id":"7242bcb9ab3e4a5f","repo":"hashicorp/nomad","slug":"cannot-give-both-an-address-and-id","errorCode":null,"errorMessage":"cannot give both an address and id","messagePattern":"cannot give both an address and id","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"command/operator_raft_leadership_transfer.go","lineNumber":110,"sourceCode":"\tif err := raftTransferLeadership(peerAddress, peerID, operator); err != nil {\n\t\tc.Ui.Error(fmt.Sprintf(\"Error transferring leadership to peer: %v\", err))\n\t\treturn 1\n\t}\n\tif peerAddress != \"\" {\n\t\tc.Ui.Output(fmt.Sprintf(\"Transferred leadership to peer with address %q\", peerAddress))\n\t} else {\n\t\tc.Ui.Output(fmt.Sprintf(\"Transferred leadership to peer with id %q\", peerID))\n\t}\n\n\treturn 0\n}\n\nfunc raftTransferLeadership(address, id string, operator *api.Operator) error {\n\tif len(address) == 0 && len(id) == 0 {\n\t\treturn fmt.Errorf(\"an address or id is required for the destination peer\")\n\t}\n\tif len(address) > 0 && len(id) > 0 {\n\t\treturn fmt.Errorf(\"cannot give both an address and id\")\n\t}\n\n\t// Try to perform the leadership transfer.\n\tif len(address) > 0 {\n\t\tif err := operator.RaftTransferLeadershipByAddress(address, nil); err != nil {\n\t\t\treturn err\n\t\t}\n\t} else {\n\t\tif err := operator.RaftTransferLeadershipByID(id, nil); err != nil {\n\t\t\treturn err\n\t\t}\n\t}\n\n\treturn nil\n}\n","sourceCodeStart":92,"sourceCodeEnd":126,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/command/operator_raft_leadership_transfer.go#L92-L126","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Remove one of the two flags — pass only -peer-address or only -peer-id.","Use -peer-id when you have the Raft ID from `nomad operator raft list-peers`; use -peer-address (host:port) otherwise.","If flags come from a script/template, ensure only one is populated and the other is empty/omitted."],"exampleFix":"// before\nnomad operator raft transfer-leadership -peer-address 127.0.0.1:4647 -peer-id 2b7f0a42-5f60\n\n// after\nnomad operator raft transfer-leadership -peer-id 2b7f0a42-5f60","handlingStrategy":"validation","validationCode":"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');","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Build command flags programmatically and emit only the one that is set.","Prefer -peer-id taken from `nomad operator raft list-peers`.","Add a script-level assertion that exactly one selector flag is non-empty."],"tags":["cli","raft","argument-validation","nomad"],"backgroundTag":"mutually-exclusive-flags","analyzedSha":"482b49bf1aec006f089bcfc7e632d8f6ac303e5e","analyzedAt":"2026-09-04T07:54:14.808Z","contentChangedAt":"2026-09-04T07:54:14.808Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}