nats-io/nats-server · error
pattern requires 6 fields, got
Error message
pattern requires 6 fields, got %d
What it means
parseCron validates that a cron pattern consists of exactly 6 whitespace-separated fields (sec min hour dom month dow). Patterns with fewer or more fields fail immediately before any field parsing. Message schedules (via parseMsgSchedule) funnel through this parser.
Solutions
- Add a seconds field so the pattern has exactly 6 fields: "0 30 2 * * *" (sec min hour dom mon dow)
- Remove any extra fields such as year
- Use the schedule format alternative if a cron expression is not required
Example fix
// before schedule := "30 2 * * *" // after schedule := "0 30 2 * * *"
Defensive patterns
Strategy: validation
Validate before calling
func validateCron6(p string) error {
if n := len(strings.Fields(p)); n != 6 {
return fmt.Errorf("cron needs 6 fields, got %d", n)
}
return nil
} Try / catch
if _, err := parseCron(pattern, loc, time.Now().Unix()); err != nil {
log.Fatalf("invalid schedule %q: %v", pattern, err)
} Prevention
- Remember this parser requires seconds as the first field (6 fields total)
- Test schedules with parseCron at startup, not at first use
- Convert 5-field crontab entries by prefixing a seconds field
When it happens
Trigger: Scheduling a message (e.g. schedule-based message delivery in JetStream) with a cron string like "0 0 12 * *" (5 fields) or "0 0 12 * * * 2026" (7 fields).
Common situations: Copy-pasting a standard 5-field crontab entry, which omits the seconds field that this parser requires; appending a year field that is unsupported.
Related errors
- beginning of range ( ) below minimum ( )
- beginning of range ( ) beyond end of range ( )
- end of range ( ) above maximum ( )
- failed to parse int from
- negative number ( ) not allowed
AI-assisted analysis of nats-io/nats-server@3a66a489d2 (2026-09-02).
Data as JSON: /api/errors/6351bd13244b18f9.
Report an issue: GitHub.
Appendix: source
Thrown at server/cron.go:52
// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package server
import (
"errors"
"fmt"
"math"
"strconv"
"strings"
"time"
)
// parseCron parses the given cron pattern and returns the next time it will fire based on the provided ts.
func parseCron(pattern string, loc *time.Location, ts int64) (time.Time, error) {
fields := strings.Fields(pattern)
if len(fields) != 6 {
return time.Time{}, fmt.Errorf("pattern requires 6 fields, got %d", len(fields))
}
// If no time zone is passed, default to UTC.
if loc == nil {
loc = time.UTC
}
// Parse each field.
var err error
var second, minute, hour, dayOfMonth, month, dayOfWeek uint64
if second, err = getField(fields[0], seconds); err != nil {
return time.Time{}, err
}
if minute, err = getField(fields[1], minutes); err != nil {
return time.Time{}, err
}
if hour, err = getField(fields[2], hours); err != nil {
return time.Time{}, errView on GitHub (pinned to 3a66a489d2)