cilium/cilium · error
failed to apply option: %w
Error message
failed to apply option: %w
What it means
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.
Source
Thrown at pkg/hubble/observer/local_observer.go:83
// numObservedFlows counts how many flows have been observed
numObservedFlows atomic.Uint64
nsManager namespace.Manager
}
// NewLocalServer returns a new local observer server.
func NewLocalServer(
payloadParser parser.Decoder,
nsManager namespace.Manager,
logger *slog.Logger,
options ...observeroption.Option,
) (*LocalObserverServer, error) {
opts := observeroption.Default // start with defaults
options = append(options, DefaultOptions...)
for _, opt := range options {
if err := opt(&opts); err != nil {
return nil, fmt.Errorf("failed to apply option: %w", err)
}
}
logger.Info(
"Configuring Hubble server",
logfields.MaxFlows, opts.MaxFlows,
logfields.EventQueueSize, opts.MonitorBuffer,
)
s := &LocalObserverServer{
log: logger,
ring: container.NewRing(opts.MaxFlows),
events: make(chan *observerTypes.MonitorEvent, opts.MonitorBuffer),
stopped: make(chan struct{}),
payloadParser: payloadParser,
startTime: time.Now(),
nsManager: nsManager,
opts: opts,View on GitHub (pinned to ac7b90affa)
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.
Example fix
// before server, err := observer.NewLocalServer(log, nil, observeroption.WithMaxFlows(-1)) // after server, err := observer.NewLocalServer(log, nil, observeroption.WithMaxFlows(4095))
Defensive patterns
Strategy: try-catch
Validate before calling
if maxFlows <= 0 { return errors.New("maxFlows must be positive") } Try / catch
srv, err := observer.NewLocalServer(log, ring, opts...)
if err != nil {
return nil, fmt.Errorf("hubble local server init: %w", err)
} Prevention
- Validate custom option inputs before passing them
- Keep options minimal and rely on tested defaults
- Unwrap the error to identify the failing option
When it happens
Trigger: Passing an observeroption.Option whose func returns an error into NewLocalServer — commonly a custom Option setting an invalid MaxFlows or other invalid configuration value.
Common situations: Custom option functions with flawed validation, tests injecting bad options, default options failing after a library upgrade changed validation rules.
Related errors
- lost event send interval must be greater than 0
- certificate and private key are both required, but only one
- transport layer security required
- config file undefined
- no listener configured
AI-assisted analysis of cilium/cilium@ac7b90affa (2026-08-31).
Data as JSON: /api/errors/62a5ba7182eeb5d4.
Report an issue: GitHub.