{"record":{"id":"7cefb4c08895b7dc","repo":"prometheus/node_exporter","slug":"failed-to-parse-device-filter-flags-w","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_aix.go","lineNumber":59,"sourceCode":"\tdeviceFilter deviceFilter\n\tlogger       *slog.Logger\n\n\ttickPerSecond float64\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\tticks, err := tickPerSecond()\n\tif err != nil {\n\t\treturn nil, err\n\t}\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\trbytes: typedDesc{readBytesDesc, prometheus.CounterValue},\n\t\twbytes: typedDesc{writtenBytesDesc, prometheus.CounterValue},\n\t\ttime:   typedDesc{ioTimeSecondsDesc, prometheus.CounterValue},\n\n\t\tbsize: typedDesc{\n\t\t\tprometheus.NewDesc(\n\t\t\t\tprometheus.BuildFQName(namespace, diskSubsystem, \"block_size_bytes\"),\n\t\t\t\t\"Size of the block device in bytes.\",\n\t\t\t\tdiskLabelNames, nil,\n\t\t\t),\n\t\t\tprometheus.GaugeValue,\n\t\t},\n\t\tqdepth: typedDesc{\n\t\t\tprometheus.NewDesc(\n\t\t\t\tprometheus.BuildFQName(namespace, diskSubsystem, \"queue_depth\"),","sourceCodeStart":41,"sourceCodeEnd":77,"githubUrl":"https://github.com/prometheus/node_exporter/blob/17ddd77c59ba27e1508e9f7894b1e55b44d6aed3/collector/diskstats_aix.go#L41-L77","documentation":"On AIX, NewDiskstatsCollector builds a device filter from the --collector.diskstats.device-exclude / device-include style flags via newDiskstatsDeviceFilter(logger). When compiling those regular expressions fails, construction is aborted with \"failed to parse device filter flags: %w\".","triggerScenarios":"node_exporter startup (or direct NewDiskstatsCollector call) with a device filter flag whose value is not a valid regular expression, causing regexp.Compile to fail inside newDiskstatsDeviceFilter.","commonSituations":"Users passing shell-reserved characters into the flag without quoting (e.g. unescaped parens or a bare |), typos in regex syntax like 'sd[a-z](' or 'sd.*[', or copy-pasted filter patterns from other tools with different regex dialects.","solutions":["Check the wrapped error (%w) for the exact regexp compile position and fix the pattern passed to the device filter flag.","Quote the flag value in the shell: --collector.diskstats.device-exclude='^(ram|loop)\\d+$'.","Test the pattern standalone (e.g. go run with regexp.MatchString, or an online Go regex tester) before adding it to the exporter flags.","Remove the filter flag entirely to collect all devices, then re-add a corrected pattern."],"exampleFix":"// before\n--collector.diskstats.device-exclude=^(ram|loop)+$\n// after (balanced group, quoted)\n--collector.diskstats.device-exclude='^(ram|loop)\\d+$'","handlingStrategy":"validation","validationCode":"if _, err := regexp.Compile(deviceFilterFlag); err != nil {\n    return fmt.Errorf(\"invalid device filter %q: %w\", deviceFilterFlag, err)\n}","typeGuard":null,"tryCatchPattern":"if _, err := NewDiskstatsCollector(logger); err != nil {\n    if strings.Contains(err.Error(), \"failed to parse device filter flags\") {\n        log.Fatalf(\"fix --collector.diskstats.device-* regex: %v\", err)\n    }\n    log.Fatalf(\"diskstats init failed: %v\", err)\n}","preventionTips":["Single-quote regex flag values in shell scripts.","Prefer simple anchored patterns like '^(ram|loop)\\d+$'.","Test patterns in a Go RE2 regex tester before rollout.","Validate flags in config management (Ansible/Puppet) before shipping to hosts."],"tags":["aix","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"}