{"record":{"id":"c1bdee0dbb679d32","repo":"cilium/cilium","slug":"failed-to-apply-option-w","errorCode":null,"errorMessage":"failed to apply option: %w","messagePattern":"failed to apply option: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/hubble/exporter/exporter.go","lineNumber":68,"sourceCode":"var _ FlowLogExporter = (*exporter)(nil)\n\n// exporter is an implementation of OnDecodedEvent interface that writes Hubble events to a file.\ntype exporter struct {\n\tlogger     *slog.Logger\n\tencoder    Encoder\n\twriter     io.WriteCloser\n\tflow       *flowpb.Flow\n\taggregator *AggregatorRunner\n\topts       Options\n}\n\n// NewExporter initializes an\n// NOTE: Stopped instances cannot be restarted and should be re-created.\nfunc NewExporter(logger *slog.Logger, options ...Option) (*exporter, error) {\n\topts := DefaultOptions // start with defaults\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\tlogger.Info(\n\t\t\"Configuring Hubble event exporter\",\n\t\tlogfields.Options, opts,\n\t)\n\treturn newExporter(logger, opts)\n}\n\n// newExporter let's you supply your own WriteCloser for tests.\nfunc newExporter(logger *slog.Logger, opts Options) (*exporter, error) {\n\twriter, err := opts.NewWriterFunc()()\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to create writer: %w\", err)\n\t}\n\tencoder, err := opts.NewEncoderFunc()(writer)\n\tif err != nil {\n\t\twriter.Close()","sourceCodeStart":50,"sourceCodeEnd":86,"githubUrl":"https://github.com/cilium/cilium/blob/ac7b90affa4baf0642e6685319d56907b3a73a6d/pkg/hubble/exporter/exporter.go#L50-L86","documentation":"NewExporter (pkg/hubble/exporter/exporter.go:68) starts from DefaultOptions and applies each Option in order; if any option function returns an error, construction aborts immediately with this wrapper so the underlying option failure is preserved. Options here include allow/deny filters and writer/encoder setup, which validate their arguments before mutating opts.","triggerScenarios":"Any Option passed to NewExporter returns a non-nil error — typically an invalid filter expression in WithAllowList/WithDenyList (unparseable flow filter), or a custom Option validating its inputs and failing.","commonSituations":"Passing a malformed Hubble flow filter (bad CEL expression, unknown field) to the allow/deny list; wiring flags into filters where an empty or typo'd value slips through; a custom Option with its own validation returning an error.","solutions":["Read the wrapped inner error to identify which option failed and why.","Fix the filter expression/arguments passed to WithAllowList/WithDenyList (validate filters before startup).","Test each option independently by calling it against DefaultOptions in a unit test.","If a custom Option fails, correct its validation or the inputs it receives."],"exampleFix":"// before\nfl, err := flow.ParseFlows([]string{\"verdict=DROPPED tcp-port=\"}) // bad filter\nexp, err := exporter.NewExporter(logger, exporter.WithAllowList(logger, fl))\n\n// after\nfl, err := flow.ParseFlows([]string{\"verdict=DROPPED\"})\nif err != nil { log.Fatal(err) }\nexp, err := exporter.NewExporter(logger, exporter.WithAllowList(logger, fl))","handlingStrategy":"validation","validationCode":"opts := exporter.DefaultOptions\nfor _, opt := range options {\n    if err := opt(&opts); err != nil {\n        return fmt.Errorf(\"pre-flight option check failed: %w\", err)\n    }\n}","typeGuard":null,"tryCatchPattern":"exp, err := exporter.NewExporter(logger, opts...)\nif err != nil {\n    if strings.Contains(err.Error(), \"failed to apply option\") {\n        log.Errorf(\"invalid exporter option/filter configuration: %v\", err)\n        return nil\n    }\n    return err\n}","preventionTips":["Validate filter expressions (ParseFlows) and fail fast at flag-parsing time.","Never pass empty strings through to filter options from CLI/env values.","Unit-test the exact option chain used in production startup."],"tags":["options","config","filter-validation","hubble"],"backgroundTag":"invalid-option-value","analyzedSha":"ac7b90affa4baf0642e6685319d56907b3a73a6d","analyzedAt":"2026-08-31T18:27:15.868Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}