{"record":{"id":"a48a2e0fde4acc13","repo":"matryer/xbar","slug":"bad-interval-value-s","errorCode":null,"errorMessage":"bad interval value: %s","messagePattern":"bad interval value: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"pkg/plugins/refresh_interval.go","lineNumber":162,"sourceCode":"\treturn interval\n}\n\nfunc parseInterval(interval string) (RefreshInterval, error) {\n\tvar (\n\t\tunit   string\n\t\tvalStr string\n\t)\n\tswitch {\n\tcase strings.HasSuffix(interval, \"ms\"):\n\t\tunit = \"ms\"\n\t\tvalStr = interval[:len(interval)-2]\n\tdefault:\n\t\tunit = string(interval[len(interval)-1])\n\t\tvalStr = interval[:len(interval)-1]\n\t}\n\tval, err := strconv.ParseInt(valStr, 10, 64)\n\tif err != nil {\n\t\treturn defaultRefreshInterval, errors.Errorf(\"bad interval value: %s\", valStr)\n\t}\n\tswitch unit {\n\tcase \"d\": // turn days into hours\n\t\treturn RefreshInterval{N: val, Unit: \"days\"}, nil\n\tcase \"h\":\n\t\treturn RefreshInterval{N: val, Unit: \"hours\"}, nil\n\tcase \"m\":\n\t\treturn RefreshInterval{N: val, Unit: \"minutes\"}, nil\n\tcase \"s\":\n\t\treturn RefreshInterval{N: val, Unit: \"seconds\"}, nil\n\tcase \"ms\":\n\t\treturn RefreshInterval{N: val, Unit: \"milliseconds\"}, nil\n\tdefault:\n\t\treturn defaultRefreshInterval, errors.Errorf(\"bad interval unit: %s\", string(unit))\n\t}\n}\n","sourceCodeStart":144,"sourceCodeEnd":179,"githubUrl":"https://github.com/matryer/xbar/blob/d624239058997c80118eaebe2e7f8331b3c765e0/pkg/plugins/refresh_interval.go#L144-L179","documentation":"parseInterval splits the interval token into a numeric part and unit suffix, then uses strconv.ParseInt on the numeric part. If the number does not parse, it returns defaultRefreshInterval and errors.Errorf(\"bad interval value: %s\", valStr). ParseFilenameInterval then re-wraps this with the filename. The value part must be a plain base-10 integer.","triggerScenarios":"ParseFilenameInterval on a filename whose interval token has a non-integer value: \"weather.5m.py\" mis-typed as \"weather..m.py\" (valStr \"\" fails), \"weather.5.5m.py\" (valStr \"5.5\"), or \"weather.fivem.py\" (valStr \"five\").","commonSituations":"Fractional intervals like 1.5h written into filenames; typos after manual renames; interval token accidentally including extra characters from the name; plugin authors writing 0-prefix or signed values like +5m (actually +5 parses fine, but spaces do not).","solutions":["Edit the plugin filename so the value is a bare integer: 1.5h -> 90m, 0.5d -> 12h","If you control the input, strip whitespace and validate with a regexp like ^\\d+(ms|d|h|m|s)$ before parsing/renaming","Rely on the returned default interval (1 minute) if the file cannot be renamed and the error is non-fatal"],"exampleFix":"// before\n// file: weather.1.5h.py -> bad interval value: 5.5h\niv, err := plugins.ParseFilenameInterval(\"weather.1.5h.py\")\n// after\n// rename to weather.90m.py\niv, err := plugins.ParseFilenameInterval(\"weather.90m.py\") // -> {90, minutes}","handlingStrategy":"type-guard","validationCode":"var tokenRe = regexp.MustCompile(`^(\\d+)(ms|[dhms])$`)\nfunc intervalTokenValid(name string) bool {\n    tok := lastDottedSegment(strings.TrimSuffix(name, \".stp\"))\n    return tok == \"\" || tokenRe.MatchString(tok)\n}","typeGuard":null,"tryCatchPattern":"iv, err := plugins.ParseFilenameInterval(filename)\nif err != nil && strings.Contains(err.Error(), \"bad interval value\") {\n    // value part was not an integer; fall back to default already returned\n    iv = plugins.RefreshInterval{N: 1, Unit: \"minutes\"}\n}","preventionTips":["Keep the numeric part of interval tokens a bare base-10 integer (no fractions, no spaces)","Convert fractional intervals (1.5h) to whole smaller units (90m) when renaming files","Validate plugin filenames with a regexp before installing"],"tags":["go","parsing","strconv","filenames"],"backgroundTag":"invalid-argument-value","analyzedSha":"d624239058997c80118eaebe2e7f8331b3c765e0","analyzedAt":"2026-09-02T22:38:22.007Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-10T02:17:09.455Z"}