{"record":{"id":"62a5ba7182eeb5d4","repo":"cilium/cilium","slug":"failed-to-apply-option-w-62a5ba","errorCode":null,"errorMessage":"failed to apply option: %w","messagePattern":"failed to apply option: %w","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/hubble/observer/local_observer.go","lineNumber":83,"sourceCode":"\n\t// numObservedFlows counts how many flows have been observed\n\tnumObservedFlows atomic.Uint64\n\n\tnsManager namespace.Manager\n}\n\n// NewLocalServer returns a new local observer server.\nfunc NewLocalServer(\n\tpayloadParser parser.Decoder,\n\tnsManager namespace.Manager,\n\tlogger *slog.Logger,\n\toptions ...observeroption.Option,\n) (*LocalObserverServer, error) {\n\topts := observeroption.Default // start with defaults\n\toptions = append(options, DefaultOptions...)\n\tfor _, opt := range options {\n\t\tif err := opt(&opts); err != nil {\n\t\t\treturn nil, fmt.Errorf(\"failed to apply option: %w\", err)\n\t\t}\n\t}\n\n\tlogger.Info(\n\t\t\"Configuring Hubble server\",\n\t\tlogfields.MaxFlows, opts.MaxFlows,\n\t\tlogfields.EventQueueSize, opts.MonitorBuffer,\n\t)\n\n\ts := &LocalObserverServer{\n\t\tlog:           logger,\n\t\tring:          container.NewRing(opts.MaxFlows),\n\t\tevents:        make(chan *observerTypes.MonitorEvent, opts.MonitorBuffer),\n\t\tstopped:       make(chan struct{}),\n\t\tpayloadParser: payloadParser,\n\t\tstartTime:     time.Now(),\n\t\tnsManager:     nsManager,\n\t\topts:          opts,","sourceCodeStart":65,"sourceCodeEnd":101,"githubUrl":"https://github.com/cilium/cilium/blob/ac7b90affa4baf0642e6685319d56907b3a73a6d/pkg/hubble/observer/local_observer.go#L65-L101","documentation":"NewLocalServer applies each observeroption.Option to the opts struct and aborts construction if any option returns an error, wrapping it with \"failed to apply option\". This surfaces invalid or conflicting server options (e.g. invalid MaxFlows, bad flow buffer settings) before the local Hubble observer server is created.","triggerScenarios":"Passing an observeroption.Option whose func returns an error into NewLocalServer — commonly a custom Option setting an invalid MaxFlows or other invalid configuration value.","commonSituations":"Custom option functions with flawed validation, tests injecting bad options, default options failing after a library upgrade changed validation rules.","solutions":["Fix the underlying option that returned the error (inspect the wrapped cause via %w / errors.Unwrap).","Validate option values (e.g. MaxFlows > 0) before passing them to NewLocalServer.","If defaults are implicated, pass explicit valid options to override them."],"exampleFix":"// before\nserver, err := observer.NewLocalServer(log, nil, observeroption.WithMaxFlows(-1))\n// after\nserver, err := observer.NewLocalServer(log, nil, observeroption.WithMaxFlows(4095))","handlingStrategy":"try-catch","validationCode":"if maxFlows <= 0 { return errors.New(\"maxFlows must be positive\") }","typeGuard":null,"tryCatchPattern":"srv, err := observer.NewLocalServer(log, ring, opts...)\nif err != nil {\n    return nil, fmt.Errorf(\"hubble local server init: %w\", err)\n}","preventionTips":["Validate custom option inputs before passing them","Keep options minimal and rely on tested defaults","Unwrap the error to identify the failing option"],"tags":["options","configuration","observer","hubble"],"backgroundTag":"option-application-failed","analyzedSha":"ac7b90affa4baf0642e6685319d56907b3a73a6d","analyzedAt":"2026-08-31T18:27:15.868Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}