Sign up (with export icon)

Watchdog

Api-class icon class

An abstract watchdog class that handles most of the error handling process and the state of the underlying component.

See the Watchdog feature guide to learn the rationale behind it and how to use it.

Properties

  • Chevron-right icon

    crashes : Array<object>
    readonly

    An array of crashes saved as an object with the following properties:

    • message: String,
    • stack: String,
    • date: Number,
    • filename: String | undefined,
    • lineno: Number | undefined,
    • colno: Number | undefined,
  • Chevron-right icon

    Specifies the state of the item watched by the watchdog. The state can be one of the following values:

    • initializing – Before the first initialization, and after crashes, before the item is ready.
    • ready – A state when the user can interact with the item.
    • crashed – A state when an error occurs. It quickly changes to initializing or crashedPermanently depending on how many and how frequent errors have been caught recently.
    • crashedPermanently – A state when the watchdog stops reacting to errors and keeps the item it is watching crashed,
    • destroyed – A state when the item is manually destroyed by the user after calling watchdog.destroy().
  • Chevron-right icon

    _item : unknown
    internalreadonly

  • Chevron-right icon

    _boundErrorHandler : ( evt: ErrorEvent | PromiseRejectionEvent ) => void
    Lock icon private

    Checks if the event error comes from the underlying item and restarts the item.

  • Chevron-right icon

    _crashNumberLimit : number
    Lock icon private

  • Chevron-right icon

    _listeners : Record<string, Array<( args: any ) => void>>
    Lock icon private

    A dictionary of event emitter listeners.

  • Chevron-right icon

    _minimumNonErrorTimePeriod : number
    Lock icon private

  • Chevron-right icon

    _now : () => number
    Lock icon private

    Returns the result of the Date.now() call. It can be overridden in tests to mock time as some popular approaches like sinon.useFakeTimers() do not work well with error handling.

Methods

  • Chevron-right icon

    constructor( config )

    Parameters

    config : WatchdogConfig

    The watchdog plugin configuration.

  • Chevron-right icon

    destroy() → void

    Destroys the watchdog and releases the resources.

    Returns

    void
  • Chevron-right icon

    off( eventName, callback ) → void

    Stops listening to the specified event name by removing the callback from event listeners.

    Note that this method differs from the CKEditor 5's default EventEmitterMixin implementation.

    Parameters

    eventName : keyof WatchdogEventMap

    The event name.

    callback : unknown

    A callback which will be removed from event listeners.

    Returns

    void
  • Chevron-right icon

    on( eventName, callback ) → void

    Starts listening to a specific event name by registering a callback that will be executed whenever an event with a given name fires.

    Note that this method differs from the CKEditor 5's default EventEmitterMixin implementation.

    Type parameters

    K : extends keyof WatchdogEventMap

    Parameters

    eventName : K

    The event name.

    callback : WatchdogEventCallback<K>

    A callback which will be added to event listeners.

    Returns

    void
  • Chevron-right icon

    _isErrorComingFromThisItem( error ) → boolean
    internal

    Traverses the error context and the watched item to find out whether the error should be handled by the given item.

    Parameters

    error : CKEditorError

    Returns

    boolean
  • Chevron-right icon

    _fire( eventName, args ) → void
    protected

    Fires an event with a given event name and arguments.

    Note that this method differs from the CKEditor 5's default EventEmitterMixin implementation.

    Type parameters

    K : extends keyof WatchdogEventMap

    Parameters

    eventName : K
    args : WatchdogEventArgs<K>

    Returns

    void
  • Chevron-right icon

    _restart() → Promise<unknown>
    protected

    The method responsible for restarting the watched item.

    Returns

    Promise<unknown>
  • Chevron-right icon

    _startErrorHandling() → void
    protected

    Starts error handling by attaching global error handlers.

    Returns

    void
  • Chevron-right icon

    _stopErrorHandling() → void
    protected

    Stops error handling by detaching global error handlers.

    Returns

    void
  • Chevron-right icon

    _handleError( error, evt ) → void
    Lock icon private

    Checks if an error comes from the watched item and restarts it. It reacts to CKEditorError errors only.

    Parameters

    error : Error

    Error.

    evt : ErrorEvent | PromiseRejectionEvent

    An error event.

    Returns

    void

    Fires

  • Chevron-right icon

    _shouldReactToError( error ) → boolean
    Lock icon private

    Checks whether an error should be handled by the watchdog.

    Parameters

    error : Error

    An error that was caught by the error handling process.

    Returns

    boolean
  • Chevron-right icon

    _shouldRestart() → boolean
    Lock icon private

    Checks if the watchdog should restart the underlying item.

    Returns

    boolean

Events

  • Chevron-right icon

    error( eventInfo, <anonymous> )

    Fired when a new CKEditorError error connected to the watchdog instance occurs and the watchdog will react to it.

    watchdog.on( 'error', ( evt, { error, causesRestart } ) => {
    	console.log( 'An error occurred.' );
    } );
    
    Copy code

    Parameters

    eventInfo : EventInfo

    An object containing information about the fired event.

    <anonymous> : WatchdogErrorEventData
  • Chevron-right icon

    stateChange( eventInfo )

    Fired when the watchdog state changed.

    Parameters

    eventInfo : EventInfo

    An object containing information about the fired event.