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
- Add --every N (seconds) for interval jobs, e.g. `--every 300`, or --cron '0 9 * * *' for cron-expression jobs
- In scripts, guard the variable: use `--every=${EVERY:?}` or check non-empty before invoking
- 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
- Always pair `cron add` with exactly one of --every N (N>0) or --cron EXPR
- Use `${VAR:?}` or explicit checks for schedule variables in scripts
- Remember --every is seconds, not minutes
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
- %s transport does not accept command arguments
- error adding job: %w
- error loading config: %w
- invalid --host value: %w
- the --no-truncate option can only be used in conjunction wit
AI-assisted analysis of sipeed/picoclaw@49183d7e8d (2026-08-15).
Data as JSON: /api/errors/ebc032b1d5e57851.
Report an issue: GitHub.