sipeed/picoclaw · error

either --every or --cron must be specified

Error message

either --every or --cron must be specified

What it means

`picoclaw cron add` needs exactly one scheduling mode: --every N (N in seconds, internally multiplied to EveryMS) or --cron EXPR. RunE rejects the invocation when every <= 0 AND cronExp is empty - that is, neither flag was supplied or --every was 0/negative. No store is touched, so no state changes.

Source

Thrown at cmd/picoclaw/internal/cron/add.go:27

)

func newAddCommand(storePath func() string) *cobra.Command {
	var (
		name    string
		message string
		every   int64
		cronExp string
		channel string
		to      string
	)

	cmd := &cobra.Command{
		Use:   "add",
		Short: "Add a new scheduled job",
		Args:  cobra.NoArgs,
		RunE: func(cmd *cobra.Command, _ []string) error {
			if every <= 0 && cronExp == "" {
				return fmt.Errorf("either --every or --cron must be specified")
			}

			var schedule cron.CronSchedule
			if every > 0 {
				everyMS := every * 1000
				schedule = cron.CronSchedule{Kind: "every", EveryMS: &everyMS}
			} else {
				schedule = cron.CronSchedule{Kind: "cron", Expr: cronExp}
			}

			cs := cron.NewCronService(storePath(), nil)
			job, err := cs.AddJob(name, schedule, message, channel, to)
			if err != nil {
				return fmt.Errorf("error adding job: %w", err)
			}

			fmt.Printf("✓ Added job '%s' (%s)\n", job.Name, job.ID)

View on GitHub (pinned to 49183d7e8d)

Solutions

  1. Add --every N (seconds) for interval jobs, e.g. `--every 300`, or --cron '0 9 * * *' for cron-expression jobs
  2. In scripts, guard the variable: use `--every=${EVERY:?}` or check non-empty before invoking
  3. Run `picoclaw cron add --help` to confirm flag names and aliases (-e, -c)

Example fix

# before
picoclaw cron add -n daily-report -m "summarize inbox"
# after
picoclaw cron add -n daily-report -m "summarize inbox" --cron '0 9 * * *'
Defensive patterns

Strategy: validation

Validate before calling

# in shell scripts, before calling picoclaw cron add
EVERY=${EVERY:-0}
if [ "$EVERY" -le 0 ] && [ -z "${CRON:-}" ]; then
  echo "refusing: schedule missing (need --every N>0 or --cron EXPR)" >&2
  exit 2
fi

Prevention

When it happens

Trigger: `picoclaw cron add -n name -m msg` with neither --every nor --cron; or only `--every 0` / a negative --every. The check runs before NewCronService/AddJob.

Common situations: Scripts that pass `--every $EVERY` with an unset/empty variable (the token disappears); assuming a default schedule exists; flag typos so cobra never binds the value.

Related errors


AI-assisted analysis of sipeed/picoclaw@49183d7e8d (2026-08-15). Data as JSON: /api/errors/ebc032b1d5e57851. Report an issue: GitHub.