chenhg5/cc-connect · error

invalid cron expression %q: %w

Error message

invalid cron expression %q: %w

What it means

AddJob validates the job then parses job.CronExpr with robfig/cron's ParseStandard; a syntax-invalid expression produces this wrapped error containing the original parse failure. The job is not stored or scheduled.

Source

Thrown at core/cron.go:487

			}
		}
	}
	cs.cron.Start()
	slog.Info("cron: scheduler started", "jobs", len(jobs))
	return nil
}

func (cs *CronScheduler) Stop() {
	cs.cron.Stop()
}

func (cs *CronScheduler) AddJob(job *CronJob) error {
	if err := validateCronJob(job); err != nil {
		return err
	}
	job.SessionMode = NormalizeCronSessionMode(job.SessionMode)
	if _, err := cron.ParseStandard(job.CronExpr); err != nil {
		return fmt.Errorf("invalid cron expression %q: %w", job.CronExpr, err)
	}
	if err := cs.store.Add(job); err != nil {
		return err
	}
	if job.Enabled {
		return cs.scheduleJob(job)
	}
	return nil
}

func (cs *CronScheduler) RemoveJob(id string) bool {
	cs.mu.Lock()
	if entryID, ok := cs.entries[id]; ok {
		cs.cron.Remove(entryID)
		delete(cs.entries, id)
	}
	cs.mu.Unlock()
	return cs.store.Remove(id)

View on GitHub (pinned to 4000b2338a)

Solutions

  1. Fix the cron expression to standard 5-field syntax (minute hour dom mon dow), e.g. "0 9 * * *".
  2. Check the wrapped %w error for the exact offset/token that failed to parse.
  3. Validate locally with cron.ParseStandard before calling AddJob.

Example fix

// before
job.CronExpr = "99 9 * * *"
// after
job.CronExpr = "59 9 * * *"
Defensive patterns

Strategy: validation

Validate before calling

if _, err := cron.ParseStandard(expr); err != nil { return err }

Prevention

When it happens

Trigger: CronScheduler.AddJob with a CronExpr that fails standard 5-field cron parsing, e.g. "99 9 * * *", "* * *", or containing invalid characters/step values.

Common situations: Hand-written cron expressions with out-of-range minute/hour values; expressions copied from systems using 6-field (seconds) syntax; missing a field entirely.

Related errors


AI-assisted analysis of chenhg5/cc-connect@4000b2338a (2026-09-06). Data as JSON: /api/errors/d965c7b43877a1e2. Report an issue: GitHub.