temporalio/temporal · error
CronString does not have 5-7 fields
Error message
CronString does not have 5-7 fields
What it means
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.
Source
Thrown at service/worker/scheduler/calendar.go:284
}
// handle @hourly, etc.
c = handlePredefinedCronStrings(c)
// split fields
cal := schedulepb.CalendarSpec{Comment: comment}
// Use FieldsSeq to avoid building an unbounded slice; we only accept 5–7 fields.
const maxCronFields = 7
var toks [maxCronFields]string
n := 0
for tok := range strings.FieldsSeq(c) {
if n < maxCronFields {
toks[n] = tok
n++
continue
}
// More than 7 fields → invalid.
return nil, nil, "", errors.New("CronString does not have 5-7 fields")
}
switch n {
case 5:
cal.Minute, cal.Hour, cal.DayOfMonth, cal.Month, cal.DayOfWeek = toks[0], toks[1], toks[2], toks[3], toks[4]
case 6:
cal.Minute, cal.Hour, cal.DayOfMonth, cal.Month, cal.DayOfWeek, cal.Year = toks[0], toks[1], toks[2], toks[3], toks[4], toks[5]
case 7:
cal.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]
default:
return nil, nil, "", errors.New("CronString does not have 5-7 fields")
}
structured, err := parseCalendarToStructured(&cal)
if err != nil {
return nil, nil, "", err
}
return structured, nil, tzName, nilView on GitHub (pinned to bde624efd1)
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.
Example fix
// before cronSpec := "0 9 * * * root /usr/bin/backup.sh" // crontab line with command // after cronSpec := "0 9 * * *"
Defensive patterns
Strategy: validation
Validate before calling
func cronFieldCount(c string) int { return len(strings.Fields(strings.TrimSpace(c))) }
// require 5 <= n <= 7 before submitting Try / catch
if err != nil && strings.Contains(err.Error(), "does not have 5-7 fields") {
// strip extra tokens (commands, comments) and resubmit
} Prevention
- 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.
When it happens
Trigger: Passing a cron string with 8+ whitespace-separated tokens (e.g. extra descriptive words, comment text, or an appended argument) to a schedule spec.
Common situations: 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.
Related errors
- CronString has time zone but missing fields
- CronString does not have interval after @every
- %s has too many slashes
- %s missing step value
- %s has invalid Step
AI-assisted analysis of temporalio/temporal@bde624efd1 (2026-09-01).
Data as JSON: /api/errors/a81f012d961a35b7.
Report an issue: GitHub.