{"record":{"id":"bbdce4e2dbe28f21","repo":"matryer/xbar","slug":"bad-interval-value-d","errorCode":null,"errorMessage":"bad interval value: %d","messagePattern":"bad interval value: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"pkg/plugins/refresh_interval.go","lineNumber":101,"sourceCode":"\t_, err = os.Stat(oldVarFullPath)\n\tif err != nil && !os.IsNotExist(err) {\n\t\treturn \"\", RefreshInterval{}, errors.Wrap(err, \"stat plugin vars file\")\n\t}\n\tif err != nil && os.IsNotExist(err) {\n\t\t// no variable file, no probs\n\t\treturn newFilename, refreshInterval, nil\n\t}\n\tnewVarFilename := newFilename + variableJSONFileExt\n\tnewVarFullPath := filepath.Join(pluginDirectory, newVarFilename)\n\tif err := os.Rename(oldVarFullPath, newVarFullPath); err != nil {\n\t\treturn \"\", RefreshInterval{}, errors.Wrap(err, \"rename plugin vars file to new refresh interval\")\n\t}\n\treturn newFilename, refreshInterval, nil\n}\n\nfunc validateRefreshInterval(refreshInterval RefreshInterval) error {\n\tif n := refreshInterval.N; n < 1 {\n\t\treturn errors.Errorf(\"bad interval value: %d\", n)\n\t}\n\tfor _, unit := range []string{\"days\", \"hours\", \"minutes\", \"seconds\", \"milliseconds\"} {\n\t\tif refreshInterval.Unit == unit {\n\t\t\treturn nil\n\t\t}\n\t}\n\treturn errors.Errorf(\"bad interval unit: %s\", refreshInterval.Unit)\n}\n\n// ParseFilenameInterval parses the filename to extract the refresh interval\n// or returns a default if it is do so.\nfunc ParseFilenameInterval(filename string) (RefreshInterval, error) {\n\t// ignore disabled piece\n\tfilename = strings.TrimSuffix(filename, disabledPluginExtension)\n\tintervalStr := findIntervalInFilename(filename)\n\tif intervalStr == \"\" {\n\t\treturn defaultRefreshInterval, nil\n\t}","sourceCodeStart":83,"sourceCodeEnd":119,"githubUrl":"https://github.com/matryer/xbar/blob/d624239058997c80118eaebe2e7f8331b3c765e0/pkg/plugins/refresh_interval.go#L83-L119","documentation":"validateRefreshInterval rejects a RefreshInterval whose N is less than 1 with errors.Errorf(\"bad interval value: %d\"). SetRefreshInterval calls this before touching the filesystem and wraps it as 'invalid refresh interval'. The library requires a positive interval count because zero/negative durations make no scheduling sense.","triggerScenarios":"Calling plugins.SetRefreshInterval (or validateRefreshInterval in tests) with plugins.RefreshInterval{N: 0, ...} or {N: -5, ...}. Note the check is n < 1, so N must be >= 1.","commonSituations":"Unmarshaling an interval from JSON where the field is missing (N defaults to 0); a UI sending an empty/zero value; user typing 0 in a settings field; integer overflow or truncation from a float seconds value of 0.5.","solutions":["Pass N >= 1 with a valid Unit (days/hours/minutes/seconds/milliseconds) to SetRefreshInterval","Validate the parsed JSON/config before constructing RefreshInterval, rejecting N < 1 at the boundary","Coerce sub-1 values to the smallest allowed representation (e.g. 500ms as {N:500, Unit:\"milliseconds\"}) instead of {N:0.5, Unit:\"seconds\"}"],"exampleFix":"// before\niv, _ := strconv.ParseInt(userInput, 10, 64)\nerr := plugins.SetRefreshInterval(dir, path, plugins.RefreshInterval{N: iv, Unit: \"minutes\"}) // 0 -> error\n// after\niv, err := strconv.ParseInt(userInput, 10, 64)\nif err != nil || iv < 1 {\n    iv = 1\n}\n_, _, err = plugins.SetRefreshInterval(dir, path, plugins.RefreshInterval{N: iv, Unit: \"minutes\"})","handlingStrategy":"validation","validationCode":"func validInterval(iv plugins.RefreshInterval) bool {\n    return iv.N >= 1\n}\n// call: if !validInterval(iv) { iv = plugins.RefreshInterval{N: 1, Unit: \"minutes\"} }","typeGuard":null,"tryCatchPattern":"if _, _, err := plugins.SetRefreshInterval(dir, path, iv); err != nil {\n    if strings.Contains(err.Error(), \"bad interval value\") {\n        _, _, err = plugins.SetRefreshInterval(dir, path, plugins.RefreshInterval{N: 1, Unit: \"minutes\"})\n    }\n}","preventionTips":["Default zero-valued structs: never pass plugins.RefreshInterval{} straight in — N is 0","Clamp parsed user input to >= 1 before constructing the interval","Convert fractional durations to the next smaller unit instead of truncating to 0"],"tags":["go","validation","refresh-interval","input"],"backgroundTag":"invalid-argument-value","analyzedSha":"d624239058997c80118eaebe2e7f8331b3c765e0","analyzedAt":"2026-09-02T22:38:22.007Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-10T02:17:09.455Z"}