-
-
Notifications
You must be signed in to change notification settings - Fork 0
CancelTaskError
Eugene Lazutkin edited this page Feb 25, 2026
·
6 revisions
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.
- Semantic cancellation signal: Clearly indicates that a task was canceled on purpose.
-
Extends
Error: Inherits from the built-inErrortype, 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
nameto"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.
CancelTaskError is available as a named and default export.
import CancelTaskError from 'time-queues/CancelTaskError.js';See Error for common properties.
-
Extends:
Error
new CancelTaskError(message?: string, options?: ErrorOptions);-
message: The error message. Default is'Task was canceled'. -
options: StandardErrorOptions, supports{cause}for error chaining.
import CancelTaskError from 'time-queues/CancelTaskError.js';
try {
// ... task execution
} catch (error) {
if (error instanceof CancelTaskError) {
console.log('Task was canceled');
}
}-
Distinguishing cancellation from errors: Use
instanceof CancelTaskErrorto 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.
- MicroTask - Task class that uses CancelTaskError
- MicroTaskQueue - Queue that cancels tasks with this error