{"record":{"id":"10d9a6f2b13aeb6e","repo":"hashicorp/nomad","slug":"an-address-or-id-is-required-for-the-destination-p","errorCode":null,"errorMessage":"an address or id is required for the destination peer","messagePattern":"an address or id is required for the destination peer","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"command/operator_raft_leadership_transfer.go","lineNumber":107,"sourceCode":"\t}\n\toperator := client.Operator()\n\n\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}","sourceCodeStart":89,"sourceCodeEnd":125,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/command/operator_raft_leadership_transfer.go#L89-L125","documentation":"raftTransferLeadership validates that exactly one of -peer-address or -peer-id is provided before calling the Operator API to transfer Raft leadership. When both are empty it returns this error, since the destination peer cannot be determined. The command surfaces it via `Error transferring leadership to peer:`.","triggerScenarios":"Running `nomad operator raft transfer-leadership` with neither -peer-address nor -peer-id set.","commonSituations":"Forgetting both flags entirely, or setting them via a script/config where empty variables expand to blank values (e.g. -peer-address=\"\" -peer-id=\"\").","solutions":["Pass exactly one destination flag, e.g. -peer-id=\"<server-id>\" or -peer-address=\"10.0.0.5:4647\".","Look up valid peer values with `nomad operator raft list-peers` before transferring.","In scripts, fail fast if the resolved peer variable is empty instead of invoking the command with blank flags."],"exampleFix":"// before\nnomad operator raft transfer-leadership\n// after\nnomad operator raft transfer-leadership -peer-id=\"f0b1d0cc-...\"","handlingStrategy":"validation","validationCode":"if (peerAddress == \"\") == (peerID == \"\") {\n    return fmt.Errorf(\"provide exactly one of -peer-address or -peer-id\")\n}","typeGuard":null,"tryCatchPattern":"if err := raftTransferLeadership(addr, id, operator); err != nil {\n    c.Ui.Error(fmt.Sprintf(\"Error transferring leadership to peer: %v\", err))\n    return 1\n}","preventionTips":["Run `nomad operator raft list-peers` first and copy the exact peer-id or address.","In scripts, assert the peer variable is non-empty before invoking the command.","Remember the rule is XOR: exactly one of -peer-address / -peer-id, never both and never neither."],"tags":["cli","raft","validation","nomad"],"backgroundTag":"missing-required-argument","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"}