hashicorp/nomad · error

invalid start time in schedule

Error message

invalid start time in schedule: %q; %w

What it means

Runtime error in TaskScheduleCron.Next: cronexpr.Parse rejects the cron.start expression (it should already have passed validation, so this indicates an expression that is structurally well-formed but semantically invalid).

Solutions

  1. Correct the cron.start expression so cronexpr can parse it
  2. Verify field ranges (e.g. hours 0-23) match the intended schedule
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at nomad/structs/task_sched.go:135 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/cbbc6dcae88b0573. Report an issue: GitHub.

Appendix: source

Thrown at nomad/structs/task_sched.go:135

func (t TaskScheduleCron) GetTimezone() string {
	if t.Timezone == "" {
		return "Local" // https://pkg.go.dev/time#LoadLocation
	}
	return t.Timezone
}

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

View on GitHub (pinned to 482b49bf1a)