hashicorp/nomad · error

invalid end time in schedule: %q; %w

Error message

invalid end time in schedule: %q; %w

What it means

Runtime error in TaskScheduleCron.Next: cronexpr.Parse rejects the cron.end expression (Nomad appends " * * * *" to build the full pause-time expression). The 2-field end value is invalid for the parser.

Source

Thrown at nomad/structs/task_sched.go:141

func (t TaskScheduleCron) Next(from time.Time) (time.Duration, time.Duration, error) {
	// where are we?
	location, err := time.LoadLocation(t.GetTimezone())
	if err != nil {
		return 0, 0, fmt.Errorf("invalid timezone in schedule: %w", err)
	}
	from = from.In(location)

	// values should be pre-validated by this point
	start, err := cronexpr.Parse(t.Start)
	if err != nil {
		return 0, 0, fmt.Errorf("invalid start time in schedule: %q; %w", t.Start, err)
	}
	// get end time for prev to see if we're within the run schedule,
	// and from next to get the next pause time.
	end, err := cronexpr.Parse(t.End + " * * * *") // TODO: if we want to exclude seconds, prefix "* " + t.End here
	if err != nil {
		return 0, 0, fmt.Errorf("invalid end time in schedule: %q; %w", t.End, err)
	}

	startNext := start.Next(from)
	// we'll check the previous start to see if we are currently between it
	// and the previous run's end, i.e. it should be running right now!
	startPrev := start.Next(from.Add(-24 * time.Hour))

	// generate ends from starts, so they always come after
	endNext := end.Next(startNext)
	endPrev := end.Next(startPrev)

	// next end must be on the same day as next start
	if endNext.Day() > startNext.Day() {
		return 0, 0, fmt.Errorf("end cannot be sooner than start; end=%q, start=%q", endNext, startNext)
	}

	// we're in the midst of it right now!
	if startPrev.Before(from) && endPrev.After(from) {

View on GitHub (pinned to 482b49bf1a)

Solutions

  1. Fix cron.end so the padded expression parses (valid hour/dom values)
  2. Use a simple end like "17 *" for 5pm daily
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at nomad/structs/task_sched.go:141 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of hashicorp/nomad@482b49bf1a (2026-09-04). Data as JSON: /api/errors/f33e052aeb9a62cf. Report an issue: GitHub.