{"record":{"id":"956953ae845bbb1d","repo":"hyperledger/fabric","slug":"targetpeer-must-be-specified-for-channel-less-op","errorCode":null,"errorMessage":"--targetPeer must be specified for channel-less operation using connection profile","messagePattern":"--targetPeer must be specified for channel-less operation using connection profile","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/peer/lifecycle/chaincode/client_connections.go","lineNumber":156,"sourceCode":"\tif len(input.TLSRootCertFiles) != len(input.PeerAddresses) {\n\t\treturn errors.Errorf(\"number of peer addresses (%d) does not match the number of TLS root cert files (%d)\", len(input.PeerAddresses), len(input.TLSRootCertFiles))\n\t}\n\n\treturn nil\n}\n\nfunc (c *ClientConnectionsInput) parseConnectionProfile() error {\n\tnetworkConfig, err := common.GetConfig(c.ConnectionProfilePath)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tc.PeerAddresses = []string{}\n\tc.TLSRootCertFiles = []string{}\n\n\tif c.ChannelID == \"\" {\n\t\tif c.TargetPeer == \"\" {\n\t\t\treturn errors.New(\"--targetPeer must be specified for channel-less operation using connection profile\")\n\t\t}\n\t\treturn c.appendPeerConfig(networkConfig, c.TargetPeer)\n\t}\n\n\tif len(networkConfig.Channels[c.ChannelID].Peers) == 0 {\n\t\treturn nil\n\t}\n\n\tfor peer, peerChannelConfig := range networkConfig.Channels[c.ChannelID].Peers {\n\t\tif peerChannelConfig.EndorsingPeer {\n\t\t\terr := c.appendPeerConfig(networkConfig, peer)\n\t\t\tif err != nil {\n\t\t\t\treturn err\n\t\t\t}\n\t\t}\n\t}\n\n\treturn nil","sourceCodeStart":138,"sourceCodeEnd":174,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/internal/peer/lifecycle/chaincode/client_connections.go#L138-L174","documentation":"When using a connection profile for channel-less lifecycle operations, the CLI cannot infer which peer to contact from the profile's channel section, so it requires --targetPeer to name a peer defined in the profile. This error is returned when no channel ID is given and no target peer is specified.","triggerScenarios":"Running a lifecycle command with --connectionProfile, no --channelID, and no --targetPeer; the code path clears PeerAddresses and requires TargetPeer before appendPeerConfig is called.","commonSituations":"Omitting --channelID for commands that don't need one (like queryinstalled) while relying on a connection profile without naming the peer; profile peer names not matching keys used by --targetPeer.","solutions":["Add --targetPeer <peerName> matching a key under \"peers\" in the connection profile","Or pass --channelID so peers can be resolved from the profile's channel section","Or skip the connection profile and use explicit --peerAddresses/--tlsRootCertFiles"],"exampleFix":"// before\npeer lifecycle chaincode queryinstalled --connectionProfile cp.yaml\n// after\npeer lifecycle chaincode queryinstalled --connectionProfile cp.yaml --targetPeer peer0.org1.example.com:7051","handlingStrategy":"validation","validationCode":"if connectionProfile != \"\" && channelID == \"\" && targetPeer == \"\" { return errors.New(\"--targetPeer required with connection profile and no channel\") }","typeGuard":null,"tryCatchPattern":"if err := run(cmd); err != nil && strings.Contains(err.Error(), \"--targetPeer must be specified\") { log.Fatal(\"add --targetPeer or --channelID\") }","preventionTips":["When using a connection profile without --channelID, always pass --targetPeer","Ensure --channelID is set for channel-scoped commands so peers resolve automatically","Validate flag combinations in CI before running against the network"],"tags":["fabric","connection-profile","configuration"],"backgroundTag":"missing-target-peer","analyzedSha":"2736b63f8fd5932511d56fe68b7039d15977f7f6","analyzedAt":"2026-09-04T08:52:36.465Z","contentChangedAt":"2026-09-04T08:52:36.465Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}