{"record":{"id":"bb61a4d9f94b7833","repo":"prometheus/node_exporter","slug":"failed-to-parse-device-filter-flags-w-bb61a4","errorCode":null,"errorMessage":"failed to parse device filter flags: %w","messagePattern":"failed to parse device filter flags: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"collector/diskstats_darwin.go","lineNumber":50,"sourceCode":"\ntype diskstatsCollector struct {\n\tdescs []typedDescFunc\n\n\tdeviceFilter deviceFilter\n\tlogger       *slog.Logger\n}\n\nfunc init() {\n\tregisterCollector(\"diskstats\", defaultEnabled, NewDiskstatsCollector)\n}\n\n// NewDiskstatsCollector returns a new Collector exposing disk device stats.\nfunc NewDiskstatsCollector(logger *slog.Logger) (Collector, error) {\n\tvar diskLabelNames = []string{\"device\"}\n\n\tdeviceFilter, err := newDiskstatsDeviceFilter(logger)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to parse device filter flags: %w\", err)\n\t}\n\n\treturn &diskstatsCollector{\n\t\tdescs: []typedDescFunc{\n\t\t\t{\n\t\t\t\ttypedDesc: typedDesc{\n\t\t\t\t\tdesc:      readsCompletedDesc,\n\t\t\t\t\tvalueType: prometheus.CounterValue,\n\t\t\t\t},\n\t\t\t\tvalue: func(stat *iostat.DriveStats) float64 {\n\t\t\t\t\treturn float64(stat.NumRead)\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\ttypedDesc: typedDesc{\n\t\t\t\t\tdesc: prometheus.NewDesc(\n\t\t\t\t\t\tprometheus.BuildFQName(namespace, diskSubsystem, \"read_sectors_total\"),\n\t\t\t\t\t\t\"The total number of sectors read successfully.\",","sourceCodeStart":32,"sourceCodeEnd":68,"githubUrl":"https://github.com/prometheus/node_exporter/blob/17ddd77c59ba27e1508e9f7894b1e55b44d6aed3/collector/diskstats_darwin.go#L32-L68","documentation":"On Darwin, NewDiskstatsCollector calls newDiskstatsDeviceFilter(logger) to compile the device include/exclude regex flags. An invalid regular expression in those flags makes construction fail with \"failed to parse device filter flags: %w\", so the diskstats collector is not created.","triggerScenarios":"node_exporter startup on macOS with --collector.diskstats.device-exclude (or include) set to a value that fails regexp.Compile; or a direct NewDiskstatsCollector call with the same bad flag value.","commonSituations":"Unquoted flag values mangled by the shell (e.g. disk[0-1] expanded as a glob), hand-written patterns with unbalanced brackets/parens, or patterns copied from Linux tooling using unsupported syntax.","solutions":["Read the wrapped regexp error (%w) to locate the syntax mistake and correct the flag value.","Single-quote the flag on the command line so the shell does not alter characters like [ and ].","Validate the regex with a Go regexp tester before deploying.","Drop the filter flag to confirm the collector works without it, then reintroduce a fixed pattern."],"exampleFix":"// before\n--collector.diskstats.device-exclude=disk[s\n// after\n--collector.diskstats.device-exclude='disk\\d+'","handlingStrategy":"validation","validationCode":"if _, err := regexp.Compile(deviceExclude); err != nil {\n    // reject invalid --collector.diskstats.device-exclude before start\n}","typeGuard":null,"tryCatchPattern":"if err := runExporter(); err != nil {\n    if strings.Contains(err.Error(), \"failed to parse device filter flags\") {\n        log.Fatalf(\"invalid diskstats device filter regex: %v\", err)\n    }\n    log.Fatal(err)\n}","preventionTips":["Quote flag values to prevent shell glob expansion of [ and ? characters.","Use Go/RE2-compatible syntax only in filter patterns.","Keep filter patterns in version-controlled launch configs and lint them.","Fall back to no filter if a pattern fails validation in config tooling."],"tags":["darwin","macos","diskstats","regex","cli-flag"],"backgroundTag":"invalid-regex-pattern","analyzedSha":"17ddd77c59ba27e1508e9f7894b1e55b44d6aed3","analyzedAt":"2026-09-07T17:54:06.211Z","contentChangedAt":"2026-09-07T17:54:06.211Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}