sickn33/agentic-awesome-skills · error · CronError

Invalid range "${t}" in ${fieldDef.name}

Error message

Invalid range "${t}" in ${fieldDef.name}

What it means

cron-engine's parseItem throws this when a field token contains a '-' but splitting on '-' does not yield exactly two parts, i.e. the token is malformed as a range. The library only supports simple lo-hi ranges; extra or stray hyphens are rejected before numeric parsing.

Source

Thrown at skills/cron-doctor/scripts/cron-engine.js:137

    let lo, hi;
    if (base === '*' || base === '') {
      lo = fieldDef.min; hi = fieldDef.max;
    } else if (base.includes('-')) {
      const [a, b] = base.split('-');
      lo = parseSingleNum(a.trim(), fieldDef, fieldIndex);
      hi = parseSingleNum(b.trim(), fieldDef, fieldIndex);
    } else {
      lo = parseSingleNum(base.trim(), fieldDef, fieldIndex);
      hi = fieldDef.max;
    }
    if (lo > hi) [lo, hi] = [hi, lo];
    for (let v = lo; v <= hi; v += step) addOne(values, v, fieldDef, fieldIndex);
    return;
  }

  if (t.includes('-')) {
    const parts = t.split('-');
    if (parts.length !== 2) throw new CronError(`Invalid range "${t}" in ${fieldDef.name}`, fieldIndex);
    const a = parseSingleNum(parts[0].trim(), fieldDef, fieldIndex);
    const b = parseSingleNum(parts[1].trim(), fieldDef, fieldIndex);
    addRange(values, a, b, fieldDef);
    return;
  }

  const v = parseSingleNum(t, fieldDef, fieldIndex);
  addOne(values, v, fieldDef, fieldIndex);
}

function addOne(values, v, fieldDef, fieldIndex) {
  if (fieldDef.key === 'dow' && v === 7) { values.add(0); return; }
  if (v < fieldDef.min || v > fieldDef.max) {
    throw new CronError(`Value ${v} out of range for ${fieldDef.name} (${fieldDef.min}-${fieldDef.max})`, fieldIndex);
  }
  values.add(v);
}

View on GitHub (pinned to 58d857988f)

Solutions

  1. Fix the token to a single lo-hi range, e.g. '1-3' instead of '1-2-3'
  2. Express multiple ranges as comma-separated items: '1-3,5-7'
  3. Check for stray hyphens or empty sides like '5-' or '-5' in the field named in the message

Example fix

// before
'0 0 1-2-3 * *'

// after
'0 0 1-3 * *'
Defensive patterns

Strategy: validation

Validate before calling

const RANGE_RE = /^\d+\s*-\s*\d+$/;
const ok = field.split(',').every(t => !t.includes('-') || RANGE_RE.test(t.trim()));
if (!ok) throw new Error(`Bad range in field: ${field}`);
const parsed = parseCron(expr);

Try / catch

try { parseCron(expr); } catch (e) { if (e instanceof CronError && /Invalid range/.test(e.message)) showFieldError(e.fieldIndex, e.message); else throw e; }

Prevention

When it happens

Trigger: A cron field token like '1-2-3' or a leading/trailing hyphen such as '-5' or '5-' passed to parseCron/parseField; t.split('-').length !== 2.

Common situations: Typos when hand-editing schedules, expecting day-of-week name ranges like 'MON-FRI' in this numeric-only parser, or pasting expressions from tools with different range syntax.

Related errors


AI-assisted analysis of sickn33/agentic-awesome-skills@58d857988f (2026-08-26). Data as JSON: /api/errors/d7dd73be90e72970. Report an issue: GitHub.