{"record":{"id":"cdd36505d672ac27","repo":"robfig/cron","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":"parser.go","lineNumber":334,"sourceCode":"\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\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.","sourceCodeStart":316,"sourceCodeEnd":352,"githubUrl":"https://github.com/robfig/cron/blob/bc59245fe10efaed9d51b56900192527ed733435/parser.go#L316-L352","documentation":"Thrown by mustParseInt in parser.go when a numeric token in a cron field cannot be parsed by strconv.Atoi. Any field component expected to be a plain non-negative integer (or a name like 'mon' when names are defined) that contains non-digit characters or overflows int reaches this error. The original strconv error is embedded in the message.","triggerScenarios":"Calling cron.Parse with malformed numeric tokens: 'abc' in a numeric-only field like hours ('0 * abc * * *'), '01.5', '1e3', '99999999999999999999' (overflow), a stray character like '1O' (letter O instead of zero), or a week name like 'mon' in a field with no names map.","commonSituations":"Typos in hand-written crontab strings; locale characters or invisible whitespace (BOM, non-breaking spaces) inside the spec; template substitution leaving literal placeholders like '{{.minute}}'; copying Quartz names ('JAN', 'SUN') into fields of the default parser where names aren't registered.","solutions":["Inspect the token shown after 'failed to parse int from' and correct/remove the non-numeric characters","Trim whitespace/BOM from spec strings read from files or env before parsing","Use the NewParser with built-in name support or write the numeric equivalent instead of month/day names if the parser has no names map","Validate the spec at application startup rather than lazily so bad config fails fast"],"exampleFix":"// before\ncron.Parse(\"0 0 {{.hour}} * * *\") // placeholder not substituted\n// after\nspec := fmt.Sprintf(\"0 0 %d * * *\", hour) // hour is a validated int","handlingStrategy":"validation","validationCode":"func isNumericToken(s string) bool {\n\tif s == \"\" { return false }\n\tfor _, r := range s { if r < '0' || r > '9' { return false } }\n\treturn true\n}","typeGuard":null,"tryCatchPattern":"sched, err := cron.Parse(spec)\nif err != nil {\n\treturn fmt.Errorf(\"invalid cron spec %q: %w\", spec, err)\n}","preventionTips":["Trim whitespace and BOM from specs read from files/env","Verify template placeholders are substituted before parsing","Use numeric values instead of month/day names unless the parser registers names"],"tags":["cron","parser","integer-parse","go"],"backgroundTag":"invalid-argument-format","analyzedSha":"bc59245fe10efaed9d51b56900192527ed733435","analyzedAt":"2026-09-07T00:35:06.760Z","contentChangedAt":"2026-09-07T00:35:06.760Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}