robfig/cron · error
too many slashes
Error message
too many slashes: %s
What it means
getRange splits an expression on '/' to separate the range from the step. An expression containing more than one '/' cannot be interpreted as range/step and is rejected with this error naming the expression.
Solutions
- Use at most one '/' per field component (range/step)
- Remove the duplicated step: "*/15" not "*/15/2"
- Validate fields against a pattern like ^\S+/\S+$ allowing only one slash before parsing
Example fix
// before
sched, err := p.Parse("0 */2/3 * * *")
// after
sched, err := p.Parse("0 */2 * * *") Defensive patterns
Strategy: validation
Validate before calling
if strings.Count(field, "/") > 1 {
return fmt.Errorf("field %q may contain at most one '/' step separator", field)
} Try / catch
sched, err := parser.Parse(spec)
if err != nil {
return fmt.Errorf("malformed step in cron spec %q: %w", spec, err)
} Prevention
- Use a single '/' for the step in each field
- Sanitize pasted/generated specs for stray slashes
- Validate cron fields with a strict regex before Parse
When it happens
Trigger: Specs like "*/2/3" or "1-5/2/2" in any field; accidentally doubling the step syntax or pasting a URL/path fragment into a cron field.
Common situations: Typo with repeated step separators; generated specs where a step value itself contained a slash; copy-paste of strings like "*/15" from another context plus its own step.
Understand the failure class
Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.
Related errors
- too many hyphens
- step of range should be a positive number
- multiple optionals may not be configured
- parser does not accept descriptors
- expected exactly fields, found
AI-assisted analysis of robfig/cron@bc59245fe1 (2026-09-07).
Data as JSON: /api/errors/673ef6a8b7ca6aca.
Report an issue: GitHub.
Appendix: source
Thrown at parser.go:301
switch len(rangeAndStep) {
case 1:
step = 1
case 2:
step, err = mustParseInt(rangeAndStep[1])
if err != nil {
return 0, err
}
// Special handling: "N/step" means "N-max/step".
if singleDigit {
end = r.max
}
if step > 1 {
extra = 0
}
default:
return 0, fmt.Errorf("too many slashes: %s", expr)
}
if start < r.min {
return 0, fmt.Errorf("beginning of range (%d) below minimum (%d): %s", start, r.min, expr)
}
if end > r.max {
return 0, fmt.Errorf("end of range (%d) above maximum (%d): %s", end, r.max, expr)
}
if start > end {
return 0, fmt.Errorf("beginning of range (%d) beyond end of range (%d): %s", start, end, expr)
}
if step == 0 {
return 0, fmt.Errorf("step of range should be a positive number: %s", expr)
}
return getBits(start, end, step) | extra, nil
}
View on GitHub (pinned to bc59245fe1)