{"record":{"id":"880be2dd6be68f09","repo":"hyperledger/fabric","slug":"peer-address-must-be-set","errorCode":null,"errorMessage":"peer address must be set","messagePattern":"peer address must be set","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/peer/common/peerclient.go","lineNumber":40,"sourceCode":"type PeerClient struct {\n\t*CommonClient\n}\n\n// NewPeerClientFromEnv creates an instance of a PeerClient from the global\n// Viper instance\nfunc NewPeerClientFromEnv() (*PeerClient, error) {\n\taddress, clientConfig, err := configFromEnv(\"peer\")\n\tif err != nil {\n\t\treturn nil, errors.WithMessage(err, \"failed to load config for PeerClient\")\n\t}\n\treturn newPeerClientForClientConfig(address, clientConfig)\n}\n\n// NewPeerClientForAddress creates an instance of a PeerClient using the\n// provided peer address and, if TLS is enabled, the TLS root cert file\nfunc NewPeerClientForAddress(address, tlsRootCertFile string) (*PeerClient, error) {\n\tif address == \"\" {\n\t\treturn nil, errors.New(\"peer address must be set\")\n\t}\n\n\tclientConfig := comm.ClientConfig{}\n\tclientConfig.DialTimeout = viper.GetDuration(\"peer.client.connTimeout\")\n\tif clientConfig.DialTimeout == time.Duration(0) {\n\t\tclientConfig.DialTimeout = defaultConnTimeout\n\t}\n\n\tsecOpts := comm.SecureOptions{\n\t\tUseTLS:             viper.GetBool(\"peer.tls.enabled\"),\n\t\tRequireClientCert:  viper.GetBool(\"peer.tls.clientAuthRequired\"),\n\t\tServerNameOverride: viper.GetString(\"peer.tls.serverhostoverride\"),\n\t}\n\n\tif secOpts.RequireClientCert {\n\t\tvar err error\n\t\tsecOpts.Key, secOpts.Certificate, err = getClientAuthInfoFromEnv(\"peer\")\n\t\tif err != nil {","sourceCodeStart":22,"sourceCodeEnd":58,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/internal/peer/common/peerclient.go#L22-L58","documentation":"NewPeerClientForAddress creates a PeerClient for a given peer address, but refuses to build one when the address string is empty. It is a guard against constructing a client that could never dial. The address must be a non-empty host:port string.","triggerScenarios":"Calling NewPeerClientForAddress(\"\", ...) directly, or newPeerClient resolving an empty peer address because no peer address was configured or passed on the command line.","commonSituations":"Missing --peerAddress flag on peer CLI commands; peer.address empty in core.yaml; environment variable override not set in container; programmatic use passing empty string when peer lookup failed earlier.","solutions":["Pass the peer address explicitly, e.g. NewPeerClientForAddress(\"peer0.org1.example.com:7051\", tlsRootCertFile)","Set peer.address in core.yaml or the --peerAddress CLI flag","Check the code path that produced the empty address (e.g. URL parsing returned empty host) and fix upstream"],"exampleFix":"// before\nclient, err := common.NewPeerClientForAddress(\"\", tlsCert)\n// after\nclient, err := common.NewPeerClientForAddress(\"peer0.org1.example.com:7051\", tlsCert)","handlingStrategy":"validation","validationCode":"func peerAddressConfigured() error {\n    addr := viper.GetString(\"peer.address\")\n    if addr == \"\" {\n        return errors.New(\"peer address must be provided via --peerAddress or peer.address in core.yaml\")\n    }\n    if _, _, err := net.SplitHostPort(addr); err != nil {\n        return fmt.Errorf(\"peer address %q is not host:port: %w\", addr, err)\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":"client, err := common.NewPeerClientForAddress(addr, tlsCert)\nif err != nil {\n    if strings.Contains(err.Error(), \"peer address must be set\") {\n        return fmt.Errorf(\"configure --peerAddress before invoking: %w\", err)\n    }\n    return err\n}","preventionTips":["Set peer.address in core.yaml as a default","Always pass --peerAddress on peer CLI commands","Validate host:port format before constructing clients"],"tags":["fabric","peer","client-config"],"backgroundTag":"missing-required-argument","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"}