nats-io/nats-server · error
step of range should be a positive number: %s
Error message
step of range should be a positive number: %s
What it means
getRange requires the '/' step of a cron range to be a positive integer; a step that parsed to 0 (or was explicitly '0') is rejected. Steps like '/0' produce this error rather than silently matching nothing.
Source
Thrown at server/cron.go:231
}
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
}
// parseIntOrName returns the (possibly-named) integer contained in expr.
func parseIntOrName(expr string, names map[string]uint) (uint, error) {
if names != nil {
if namedInt, ok := names[strings.ToLower(expr)]; ok {
return namedInt, nil
}
}
return mustParseInt(expr)
}
// mustParseInt parses the given expression as an int or returns an error.
func mustParseInt(expr string) (uint, error) {
num, err := strconv.Atoi(expr)
if err != nil {View on GitHub (pinned to 3a66a489d2)
Solutions
- Set the step to a positive integer, e.g. "*/5" or "1-30/2"
- Validate any programmatically-supplied step is >= 1 before building the schedule string
- Remove the '/step' suffix entirely if every unit should match
Example fix
// before expr := "*/0" // after expr := "*/1"
Defensive patterns
Strategy: validation
Validate before calling
if step := parseStep(seg); step == 0 {
return fmt.Errorf("step must be >= 1 in %q", seg)
} Prevention
- Guard programmatically-supplied steps with a >= 1 check
- Prefer omitting the step when every unit should fire
When it happens
Trigger: A cron field with a zero step, e.g. "*/0" or "1-30/0", parsed via parseCron -> getField -> getRange.
Common situations: Computing the step from a variable/config value that defaulted to 0; typo writing '/o' or '/0' intending a real interval.
Related errors
- beginning of range (%d) below minimum (%d): %s
- end of range (%d) above maximum (%d): %s
- beginning of range (%d) beyond end of range (%d): %s
- pattern requires 6 fields, got %d
- too many hyphens: %s
AI-assisted analysis of nats-io/nats-server@3a66a489d2 (2026-09-02).
Data as JSON: /api/errors/aae7e8d89f857a79.
Report an issue: GitHub.