jlcodes99/cockpit-tools · error

crontab_field_empty

crontab_field_empty

Error message

crontab_field_empty

What it means

parseCrontabField trims the whole field string first; if the result is empty there is nothing to parse for that cron position, so it throws 'crontab_field_empty'. The library requires every one of the five fields to be non-empty.

Source

Thrown at src/pages/WakeupTasksPage.tsx:520

  const single = parseCrontabNumber(rangePart);
  validateCrontabValue(single, min, max, normalizeDayOfWeek);
  if (step === 1) {
    target.add(normalizeDayOfWeek ? normalizeCrontabDayOfWeek(single) : single);
    return;
  }
  insertCrontabRange(target, single, max, step, normalizeDayOfWeek);
};

const parseCrontabField = (
  field: string,
  min: number,
  max: number,
  normalizeDayOfWeek: boolean,
): ParsedCronField => {
  const trimmed = field.trim();
  if (!trimmed) {
    throw new Error('crontab_field_empty');
  }

  if (trimmed === '*') {
    const values = new Set<number>();
    insertCrontabRange(values, min, max, 1, normalizeDayOfWeek);
    return { values, wildcard: true };
  }

  const values = new Set<number>();
  const segments = trimmed.split(',');
  if (segments.length === 0) {
    throw new Error('crontab_field_empty');
  }
  segments.forEach((segment) => {
    const normalizedSegment = segment.trim();
    if (!normalizedSegment) {
      throw new Error('crontab_segment_empty');
    }

View on GitHub (pinned to 1ed8b77992)

Solutions

  1. Supply a value for the empty field, using '*' if any value is acceptable (e.g. '* * * * *').
  2. Trim/repair the stored crontab string before parsing.
  3. Validate the expression with parseCrontabExpression in a try/catch at form level and require all five fields before saving.

Example fix

// before
parseCrontabExpression('30   * *');       // missing fields / empty parts
// after
parseCrontabExpression('30 * * * *');     // all five fields present
Defensive patterns

Strategy: validation

Validate before calling

const fieldOk = (f: string) => f.trim().length > 0;
const parts = expr.trim().split(/\s+/);
const allFieldsOk = parts.length === 5 && parts.every(fieldOk);

Type guard

const isNonEmptyField = (f: unknown): f is string =>
  typeof f === 'string' && f.trim().length > 0;

Try / catch

try {
  const parsed = parseCrontabExpression(expr);
} catch (e) {
  if ((e as Error).message === 'crontab_field_empty') {
    setFieldError('every crontab field is required; use * for any value');
  }
}

Prevention

When it happens

Trigger: parseCrontabField called with '' or a whitespace-only string for any of the five fields, e.g. parseCrontabExpression(' * * * ') after split producing an empty part, or direct calls with an empty field.

Common situations: A saved crontab string with missing fields due to a truncated export/import; UI input allowing submission before all five fields are filled; splitting on whitespace that collapses leading/trailing spaces into fewer tokens (then parts.length check may not fire but empty parts can appear from other split paths).

Related errors


AI-assisted analysis of jlcodes99/cockpit-tools@1ed8b77992 (2026-09-05). Data as JSON: /api/errors/8a172fa9649ec883. Report an issue: GitHub.