{"record":{"id":"a81f012d961a35b7","repo":"temporalio/temporal","slug":"cronstring-does-not-have-5-7-fields","errorCode":null,"errorMessage":"CronString does not have 5-7 fields","messagePattern":"CronString does not have 5-7 fields","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"service/worker/scheduler/calendar.go","lineNumber":284,"sourceCode":"\t}\n\n\t// handle @hourly, etc.\n\tc = handlePredefinedCronStrings(c)\n\n\t// split fields\n\tcal := schedulepb.CalendarSpec{Comment: comment}\n\t// Use FieldsSeq to avoid building an unbounded slice; we only accept 5–7 fields.\n\tconst maxCronFields = 7\n\tvar toks [maxCronFields]string\n\tn := 0\n\tfor tok := range strings.FieldsSeq(c) {\n\t\tif n < maxCronFields {\n\t\t\ttoks[n] = tok\n\t\t\tn++\n\t\t\tcontinue\n\t\t}\n\t\t// More than 7 fields → invalid.\n\t\treturn nil, nil, \"\", errors.New(\"CronString does not have 5-7 fields\")\n\t}\n\tswitch n {\n\tcase 5:\n\t\tcal.Minute, cal.Hour, cal.DayOfMonth, cal.Month, cal.DayOfWeek = toks[0], toks[1], toks[2], toks[3], toks[4]\n\tcase 6:\n\t\tcal.Minute, cal.Hour, cal.DayOfMonth, cal.Month, cal.DayOfWeek, cal.Year = toks[0], toks[1], toks[2], toks[3], toks[4], toks[5]\n\tcase 7:\n\t\tcal.Second, cal.Minute, cal.Hour, cal.DayOfMonth, cal.Month, cal.DayOfWeek, cal.Year = toks[0], toks[1], toks[2], toks[3], toks[4], toks[5], toks[6]\n\tdefault:\n\t\treturn nil, nil, \"\", errors.New(\"CronString does not have 5-7 fields\")\n\t}\n\n\tstructured, err := parseCalendarToStructured(&cal)\n\tif err != nil {\n\t\treturn nil, nil, \"\", err\n\t}\n\n\treturn structured, nil, tzName, nil","sourceCodeStart":266,"sourceCodeEnd":302,"githubUrl":"https://github.com/temporalio/temporal/blob/bde624efd13fbd3843654058db6d9c716166318b/service/worker/scheduler/calendar.go#L266-L302","documentation":"parseCronString tokenizes the cron string into at most 7 fields (second minute hour dayOfMonth month dayOfWeek year). If tokenization yields more than maxCronFields tokens — i.e. the string has 8 or more whitespace-separated fields — the parser rejects it as invalid because only 5-7 field cron syntax is supported.","triggerScenarios":"Passing a cron string with 8+ whitespace-separated tokens (e.g. extra descriptive words, comment text, or an appended argument) to a schedule spec.","commonSituations":"Copying crontab lines that include the command-to-run portion (user, command args) instead of only the schedule fields; strings with trailing comments or duplicated fields from bad shell interpolation; using 6-field seconds syntax plus a command.","solutions":["Remove extra tokens so only 5-7 whitespace-separated schedule fields remain (min hour dom mon dow [year] [second-first variant → 7 fields]).","Strip any trailing command/text from copied crontab entries — keep only the schedule portion.","Quote or remove internal comments; cron fields must not contain unquoted extra words.","Count fields before submitting: split on whitespace and require 5, 6, or 7 tokens."],"exampleFix":"// before\ncronSpec := \"0 9 * * * root /usr/bin/backup.sh\" // crontab line with command\n// after\ncronSpec := \"0 9 * * *\"","handlingStrategy":"validation","validationCode":"func cronFieldCount(c string) int { return len(strings.Fields(strings.TrimSpace(c))) }\n// require 5 <= n <= 7 before submitting","typeGuard":null,"tryCatchPattern":"if err != nil && strings.Contains(err.Error(), \"does not have 5-7 fields\") {\n\t// strip extra tokens (commands, comments) and resubmit\n}","preventionTips":["Never paste full crontab lines — keep only the schedule fields, not the command.","Count whitespace-separated fields before submitting; allow 5-7.","Strip trailing comments from cron strings."],"tags":["scheduler","cron","validation","go"],"backgroundTag":"malformed-cron-expression","analyzedSha":"bde624efd13fbd3843654058db6d9c716166318b","analyzedAt":"2026-09-01T07:18:39.080Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}