Skip to content

Cronus Errors

GitHub Actions edited this page Aug 21, 2026 · 4 revisions

Errors

The typed error hierarchy for @tundralibs/cronus.

Deno Bun Node.js Cloudflare Workers Browser

Table of Contents

Hierarchy

All package errors extend CronusError, which extends BaseError from Utils — so every error carries the project-wide contract: typed context, cause chains, and JSON serialisation.

BaseError (@tundralibs/utils)
└── CronusError
    ├── DuplicateJobError
    ├── JobNotFoundError
    ├── InvalidScheduleError
    └── InvalidActionError

CronusError is also used directly to wrap foreign errors thrown by job actions before they surface on the error event (the original error is preserved as cause).

Classes

Class Thrown by Context
DuplicateJobError add/addOnce — name already registered { name }
JobNotFoundError get/remove/enable/disable/isRunning/trigger — unknown name { name }
InvalidScheduleError parseSchedule (and therefore add) — malformed expression { expression, field?, reason }
InvalidActionError add — action is not a function { name }

All registration errors are thrown synchronously at the call site — never deferred to tick time — so a mis-configured job fails the deploy, not the 03:00 run.

Catching

Branch with instanceof; read structured data from context:

import {
  Cronus,
  DuplicateJobError,
  InvalidScheduleError,
} from '@tundralibs/cronus';

const cron = new Cronus();
const name = 'hourly-cleanup';
const schedule = '0 * * * *';
const action = () => {};

try {
  cron.add(name, schedule, action);
} catch (e) {
  if (e instanceof InvalidScheduleError) {
    console.error(
      `bad schedule '${e.context.expression}': ${e.context.reason}`,
    );
  } else if (e instanceof DuplicateJobError) {
    // idempotent re-registration — ignore
  } else {
    throw e;
  }
}

Related Documentation


← Back to Cronus

Clone this wiki locally