Skip to content

CancelTaskError

Eugene Lazutkin edited this page Feb 25, 2026 · 6 revisions

Description

CancelTaskError is a specialized Error subclass that represents the cancellation of a scheduled task in the time-queues system. It provides a clear, semantically meaningful way to signal that a task was intentionally canceled rather than failing due to an unexpected runtime error.

This error is thrown (or rejected with) by APIs that support task cancellation, allowing consumers to distinguish cancellation from other failure modes and handle it accordingly, such as by performing cleanup or ignoring the cancellation as a normal control-flow outcome.

This class is used to reject a promise when a task is canceled.

Key features

  • Semantic cancellation signal: Clearly indicates that a task was canceled on purpose.
  • Extends Error: Inherits from the built-in Error type, preserving standard error behavior and stack traces.
  • Default error message: Uses "Task was canceled" by default, but accepts a custom message.
  • Named error type: Sets name to "CancelTaskError" for easier discrimination in error handling logic.
  • Stack trace capture: Uses Error.captureStackTrace (when available) to provide a clean stack trace that starts at the point of construction.
  • Default export: Available both as a named and default export, depending on import style.

Technical specifications

CancelTaskError is available as a named and default export.

import CancelTaskError from 'time-queues/CancelTaskError.js';

See Error for common properties.

Class: CancelTaskError

  • Extends: Error

Constructor

new CancelTaskError(message?: string, options?: ErrorOptions);
  • message: The error message. Default is 'Task was canceled'.
  • options: Standard ErrorOptions, supports {cause} for error chaining.

Usage instructions

import CancelTaskError from 'time-queues/CancelTaskError.js';

try {
  // ... task execution
} catch (error) {
  if (error instanceof CancelTaskError) {
    console.log('Task was canceled');
  }
}

Troubleshooting

  • Distinguishing cancellation from errors: Use instanceof CancelTaskError to check if an error is a cancellation signal rather than an unexpected failure.
  • Error cause: When a task is canceled with an error, the original error is available via error.cause.

See Also

Clone this wiki locally