{"record":{"id":"52022667c743a7b0","repo":"grpc/grpc-go","slug":"grpctransport-extensions-is-not-set-in-serveriden","errorCode":null,"errorMessage":"grpctransport: Extensions is not set in ServerIdentifier","messagePattern":"grpctransport: Extensions is not set in ServerIdentifier","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/xds/clients/grpctransport/grpc_transport.go","lineNumber":94,"sourceCode":"// the credentials from provided map of credentials names to\n// credentials.Bundle.\nfunc NewBuilder(configs map[string]Config) *Builder {\n\treturn &Builder{\n\t\tconfigs:     configs,\n\t\tconnections: make(map[clients.ServerIdentifier]*grpc.ClientConn),\n\t\trefs:        make(map[clients.ServerIdentifier]int),\n\t}\n}\n\n// Build returns a gRPC-based clients.Transport.\n//\n// The Extension field of the ServerIdentifier must be a ServerIdentifierExtension.\nfunc (b *Builder) Build(si clients.ServerIdentifier) (clients.Transport, error) {\n\tif si.ServerURI == \"\" {\n\t\treturn nil, fmt.Errorf(\"grpctransport: ServerURI is not set in ServerIdentifier\")\n\t}\n\tif si.Extensions == nil {\n\t\treturn nil, fmt.Errorf(\"grpctransport: Extensions is not set in ServerIdentifier\")\n\t}\n\tsce, ok := si.Extensions.(ServerIdentifierExtension)\n\tif !ok {\n\t\treturn nil, fmt.Errorf(\"grpctransport: Extensions field is %T, but must be %T in ServerIdentifier\", si.Extensions, ServerIdentifierExtension{})\n\t}\n\n\tconfig, ok := b.configs[sce.ConfigName]\n\tif !ok {\n\t\treturn nil, fmt.Errorf(\"grpctransport: unknown config name %q specified in ServerIdentifierExtension\", sce.ConfigName)\n\t}\n\tif config.Credentials == nil {\n\t\treturn nil, fmt.Errorf(\"grpctransport: config %q has nil credentials bundle\", sce.ConfigName)\n\t}\n\n\tb.mu.Lock()\n\tdefer b.mu.Unlock()\n\n\tif cc, ok := b.connections[si]; ok {","sourceCodeStart":76,"sourceCodeEnd":112,"githubUrl":"https://github.com/grpc/grpc-go/blob/0c51461d27177d997e14c642fe18c11668fc09a3/internal/xds/clients/grpctransport/grpc_transport.go#L76-L112","documentation":"Returned by (*Builder).Build when the ServerIdentifier.Extensions field is nil (grpc_transport.go:94). The Builder requires a ServerIdentifierExtension value to know which named Config (credentials bundle) to use, so a missing extension is a programming error.","triggerScenarios":"Calling builder.Build(si) where si.Extensions == nil. This happens when a ServerIdentifier is constructed without setting the Extensions field to a grpctransport.ServerIdentifierExtension.","commonSituations":"Caller builds a clients.ServerIdentifier literal and forgets the Extensions field; an LRS or xDS client wrapper does not propagate the Extensions; refactoring dropped the field assignment.","solutions":["Set si.Extensions = grpctransport.ServerIdentifierExtension{ConfigName: \"...\"} before Build.","Centralize ServerIdentifier construction in a helper that always populates Extensions.","Add a unit test asserting Extensions is non-nil for every identifier produced."],"exampleFix":"// before\nsi := clients.ServerIdentifier{ServerURI: uri} // Extensions nil\n\n// after\nsi := clients.ServerIdentifier{\n    ServerURI:  uri,\n    Extensions: grpctransport.ServerIdentifierExtension{ConfigName: cfgName},\n}","handlingStrategy":"validation","validationCode":"func validateSI(si clients.ServerIdentifier) error {\n    if si.Extensions == nil {\n        return errors.New(\"Extensions must be set to grpctransport.ServerIdentifierExtension\")\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":"if err != nil && strings.Contains(err.Error(), \"Extensions is not set\") {\n    // set si.Extensions before retrying\n}","preventionTips":["Always populate Extensions when constructing a ServerIdentifier for grpctransport.","Provide a constructor (e.g. newServerIdentifier(uri, cfgName)) that enforces the invariant.","Code-review ServerIdentifier literals to ensure the Extensions field is set."],"tags":["grpctransport","xds","configuration","validation"],"backgroundTag":null,"analyzedSha":"0c51461d27177d997e14c642fe18c11668fc09a3","analyzedAt":"2026-08-11T14:49:15.055Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}