{"record":{"id":"ffb48687ee45c4c0","repo":"ethereum/go-ethereum","slug":"nil-auth","errorCode":null,"errorMessage":"nil auth","messagePattern":"nil auth","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"rpc/client_opt.go","lineNumber":128,"sourceCode":"\t}\n\treturn optionFunc(func(cfg *clientConfig) {\n\t\tcfg.tmprop = tmp\n\t})\n}\n\n// WithHTTPClient configures the http.Client used by the RPC client.\nfunc WithHTTPClient(c *http.Client) ClientOption {\n\treturn optionFunc(func(cfg *clientConfig) {\n\t\tcfg.httpClient = c\n\t})\n}\n\n// WithHTTPAuth configures HTTP request authentication. The given provider will be called\n// whenever a request is made. Note that only one authentication provider can be active at\n// any time.\nfunc WithHTTPAuth(a HTTPAuth) ClientOption {\n\tif a == nil {\n\t\tpanic(\"nil auth\")\n\t}\n\treturn optionFunc(func(cfg *clientConfig) {\n\t\tcfg.httpAuth = a\n\t})\n}\n\n// A HTTPAuth function is called by the client whenever a HTTP request is sent.\n// The function must be safe for concurrent use.\n//\n// Usually, HTTPAuth functions will call h.Set(\"authorization\", \"...\") to add\n// auth information to the request.\ntype HTTPAuth func(h http.Header) error\n\n// WithBatchItemLimit changes the maximum number of items allowed in batch requests.\n//\n// Note: this option applies when processing incoming batch requests. It does not affect\n// batch requests sent by the client.\nfunc WithBatchItemLimit(limit int) ClientOption {","sourceCodeStart":110,"sourceCodeEnd":146,"githubUrl":"https://github.com/ethereum/go-ethereum/blob/6bb0588ad8e7f922e4ad5580f51265a4097af08f/rpc/client_opt.go#L110-L146","documentation":"WithHTTPAuth panics when given a nil HTTPAuth provider. The option stores the authentication function that is invoked on every HTTP request; a nil function would crash later inside the request path, so the library fails fast at client construction time instead.","triggerScenarios":"Calling rpc.DialOptions(ctx, \"http://...\", rpc.WithHTTPAuth(nil)); forwarding an auth function from a config struct whose field was never set; conditionally building options and unconditionally appending a nil auth.","commonSituations":"Optional bearer-token authentication behind a config flag; switching from URL-embedded credentials to header-based auth; passing a function variable declared but not assigned (var auth rpc.HTTPAuth).","solutions":["Pass a real HTTPAuth, e.g. rpc.WithHTTPAuth(func(h http.Header) error { h.Set(\"authorization\", \"Bearer \"+tok); return nil }).","If auth is optional, only include the option when the provider is non-nil.","Check for accidental double configuration: only one authentication provider can be active at a time."],"exampleFix":"// before\nvar auth rpc.HTTPAuth // nil when no auth configured\nc, err := rpc.DialOptions(ctx, url, rpc.WithHTTPAuth(auth))\n\n// after\nvar opts []rpc.ClientOption\nif auth != nil {\n    opts = append(opts, rpc.WithHTTPAuth(auth))\n}\nc, err := rpc.DialOptions(ctx, url, opts...)","handlingStrategy":"validation","validationCode":"var opts []rpc.ClientOption\nif auth != nil {\n    opts = append(opts, rpc.WithHTTPAuth(auth))\n}\nc, err := rpc.DialOptions(ctx, url, opts...)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Guard optional-auth configuration behind a non-nil check before adding the option.","Define auth providers as package-level functions or initialized closures, never nil function variables.","Remember only one auth provider can be active; validate your config for duplicates too."],"tags":["rpc","http","authentication","nil-check","config","panic","go"],"backgroundTag":null,"analyzedSha":"6bb0588ad8e7f922e4ad5580f51265a4097af08f","analyzedAt":"2026-08-15T10:06:53.996Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}