{"record":{"id":"8312a57e0efd175c","repo":"nats-io/nats-server","slug":"failed-to-parse-int-from-s-s","errorCode":null,"errorMessage":"failed to parse int from %s: %s","messagePattern":"failed to parse int from (.+?): (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/cron.go","lineNumber":250,"sourceCode":"\t}\n\treturn getBits(start, end, step) | extra, nil\n}\n\n// parseIntOrName returns the (possibly-named) integer contained in expr.\nfunc parseIntOrName(expr string, names map[string]uint) (uint, error) {\n\tif names != nil {\n\t\tif namedInt, ok := names[strings.ToLower(expr)]; ok {\n\t\t\treturn namedInt, nil\n\t\t}\n\t}\n\treturn mustParseInt(expr)\n}\n\n// mustParseInt parses the given expression as an int or returns an error.\nfunc mustParseInt(expr string) (uint, error) {\n\tnum, err := strconv.Atoi(expr)\n\tif err != nil {\n\t\treturn 0, fmt.Errorf(\"failed to parse int from %s: %s\", expr, err)\n\t}\n\tif num < 0 {\n\t\treturn 0, fmt.Errorf(\"negative number (%d) not allowed: %s\", num, expr)\n\t}\n\treturn uint(num), nil\n}\n\n// getBits sets all bits in the range [min, max], modulo the given step size.\nfunc getBits(min, max, step uint) uint64 {\n\tvar bits uint64\n\n\t// If step is 1, use shifts.\n\tif step == 1 {\n\t\treturn ^(math.MaxUint64 << (max + 1)) & (math.MaxUint64 << min)\n\t}\n\n\t// Else, use a simple loop.\n\tfor i := min; i <= max; i += step {","sourceCodeStart":232,"sourceCodeEnd":268,"githubUrl":"https://github.com/nats-io/nats-server/blob/3a66a489d262bf89b71a71c955c94920394532f3/server/cron.go#L232-L268","documentation":"mustParseInt converts a cron field token to a non-negative integer using strconv.Atoi; any token that is not a plain valid integer produces this error wrapping the underlying strconv error. Names are resolved earlier via parseIntOrName's name map, so this fires for non-numeric, non-name tokens.","triggerScenarios":"A cron field containing invalid tokens like \"*/abc\", \"1--3\", \"1o\", empty segments (e.g. double commas \"1,,3\"), passed via getRange or parseIntOrName during parseCron.","commonSituations":"Typos in the schedule string; month/day names like \"jan\" or \"mon\" used in a field whose name map does not include them; stray whitespace collapsed into malformed tokens.","solutions":["Correct the token to a valid integer (e.g. \"*/5\" instead of \"*/abc\")","Use numeric values instead of names not supported by the field's name map","Remove stray characters/empty segments (double commas, trailing separators)"],"exampleFix":"// before (month field)\n expr := \"jan-3\"\n// after\n expr := \"1-3\"","handlingStrategy":"validation","validationCode":"func isIntToken(s string) bool {\n    _, err := strconv.Atoi(s)\n    return err == nil && s != \"\"\n}","typeGuard":null,"tryCatchPattern":"if _, err := parseCron(pattern, nil, ts); err != nil {\n    return fmt.Errorf(\"schedule %q invalid: %w\", pattern, err)\n}","preventionTips":["Use numeric tokens or supported names only","Trim and split schedule strings before storing them"],"tags":["cron","parsing","number-format"],"backgroundTag":"invalid-cron-expression","analyzedSha":"3a66a489d262bf89b71a71c955c94920394532f3","analyzedAt":"2026-09-02T04:41:54.247Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}