jlcodes99/cockpit-tools · error

crontab_segment_empty

crontab_segment_empty

Error message

crontab_segment_empty

What it means

Within parseCrontabField, each comma-separated segment is trimmed; if a segment is empty (e.g. a leading, trailing, or doubled comma) the parser throws 'crontab_segment_empty' rather than silently skipping it.

Source

Thrown at src/pages/WakeupTasksPage.tsx:537

  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');
    }
    parseCrontabSegment(normalizedSegment, min, max, normalizeDayOfWeek, values);
  });

  if (values.size === 0) {
    throw new Error('crontab_no_values');
  }
  return { values, wildcard: false };
};

const parseCrontabExpression = (expr: string): ParsedCrontab => {
  const parts = expr.trim().split(/\s+/);
  if (parts.length !== 5) {
    throw new Error('crontab_parts_must_be_five');
  }

  return {
    minute: parseCrontabField(parts[0], 0, 59, false),

View on GitHub (pinned to 1ed8b77992)

Solutions

  1. Remove stray/extra commas: '5,10' instead of '5,,10'.
  2. Filter empty segments before building the expression: values.filter(v => v.trim()).join(',').
  3. Pre-validate the field with a regex like /^(\d+(-\d+)?(\/\d+)?)(,(\d+(-\d+)?(\/\d+)?))*$/ and show an inline error.

Example fix

// before
const minuteField = ['5', '', '10'].join(',');   // '5,,10'
// after
const minuteField = ['5', '', '10'].filter(Boolean).join(',');  // '5,10'
Defensive patterns

Strategy: validation

Validate before calling

const LIST_RE = /^(\d+(-\d+)?(\/\d+)?)(,(\d+(-\d+)?(\/\d+)?))*$/;
const isValidListField = (f: string) => LIST_RE.test(f.trim());

Type guard

const hasNoEmptySegments = (f: string): boolean =>
  f.split(',').every((s) => s.trim().length > 0);

Try / catch

try {
  const parsed = parseCrontabExpression(expr);
} catch (e) {
  if ((e as Error).message === 'crontab_segment_empty') {
    setFieldError('remove empty items between commas in the field list');
  }
}

Prevention

When it happens

Trigger: A field such as '5,,10', ',5', or '5,' passed to parseCrontabField — any comma-delimited segment that trims to an empty string.

Common situations: Users editing a cron list in the Wakeup Tasks UI and leaving stray commas; programmatic joining of lists where some elements are empty strings (['5',''].join(',')).

Related errors


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