Watchdog
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
crashes : Array<object>readonlymodule:watchdog/watchdog~Watchdog#crashesAn 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,
module:watchdog/watchdog~Watchdog#stateSpecifies 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 toinitializingorcrashedPermanentlydepending 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 callingwatchdog.destroy().
_item : unknowninternalreadonlymodule:watchdog/watchdog~Watchdog#_itemThe watched item.
_boundErrorHandler : ( evt: ErrorEvent | PromiseRejectionEvent ) => voidprivatemodule:watchdog/watchdog~Watchdog#_boundErrorHandlerChecks if the event error comes from the underlying item and restarts the item.
_crashNumberLimit : numberprivatemodule:watchdog/watchdog~Watchdog#_crashNumberLimit_listeners : Record<string, Array<( args: any ) => void>>privatemodule:watchdog/watchdog~Watchdog#_listenersA dictionary of event emitter listeners.
_minimumNonErrorTimePeriod : numberprivatemodule:watchdog/watchdog~Watchdog#_minimumNonErrorTimePeriod_now : () => numberprivatemodule:watchdog/watchdog~Watchdog#_nowReturns the result of the
Date.now()call. It can be overridden in tests to mock time as some popular approaches likesinon.useFakeTimers()do not work well with error handling.
Methods
constructor( config )module:watchdog/watchdog~Watchdog#constructordestroy() → voidmodule:watchdog/watchdog~Watchdog#destroyoff( eventName, callback ) → voidmodule:watchdog/watchdog~Watchdog#offStops listening to the specified event name by removing the callback from event listeners.
Note that this method differs from the CKEditor 5's default
EventEmitterMixinimplementation.Parameters
eventName : keyof WatchdogEventMapThe event name.
callback : unknownA callback which will be removed from event listeners.
Returns
void
on( eventName, callback ) → voidmodule:watchdog/watchdog~Watchdog#onStarts 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
EventEmitterMixinimplementation.Type parameters
K : extends keyof WatchdogEventMap
Parameters
eventName : KThe event name.
callback : WatchdogEventCallback<K>A callback which will be added to event listeners.
Returns
void
_isErrorComingFromThisItem( error ) → booleaninternalmodule:watchdog/watchdog~Watchdog#_isErrorComingFromThisItemTraverses 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
_fire( eventName, args ) → voidprotectedmodule:watchdog/watchdog~Watchdog#_fireFires an event with a given event name and arguments.
Note that this method differs from the CKEditor 5's default
EventEmitterMixinimplementation.Type parameters
K : extends keyof WatchdogEventMap
Parameters
eventName : Kargs : WatchdogEventArgs<K>
Returns
void
_restart() → Promise<unknown>protectedmodule:watchdog/watchdog~Watchdog#_restartThe method responsible for restarting the watched item.
Returns
Promise<unknown>
_startErrorHandling() → voidprotectedmodule:watchdog/watchdog~Watchdog#_startErrorHandling_stopErrorHandling() → voidprotectedmodule:watchdog/watchdog~Watchdog#_stopErrorHandling_handleError( error, evt ) → voidprivatemodule:watchdog/watchdog~Watchdog#_handleErrorChecks if an error comes from the watched item and restarts it. It reacts to
CKEditorErrorerrors only.Parameters
error : ErrorError.
evt : ErrorEvent | PromiseRejectionEventAn error event.
Returns
void
Fires
_shouldReactToError( error ) → booleanprivatemodule:watchdog/watchdog~Watchdog#_shouldReactToErrorChecks whether an error should be handled by the watchdog.
Parameters
error : ErrorAn error that was caught by the error handling process.
Returns
boolean
_shouldRestart() → booleanprivatemodule:watchdog/watchdog~Watchdog#_shouldRestartChecks if the watchdog should restart the underlying item.
Returns
boolean
Events
error( eventInfo, <anonymous> )module:watchdog/watchdog~Watchdog#event:errorFired when a new
CKEditorErrorerror 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 codeParameters
eventInfo : EventInfoAn object containing information about the fired event.
<anonymous> : WatchdogErrorEventData
stateChange( eventInfo )module:watchdog/watchdog~Watchdog#event:stateChangeFired when the watchdog state changed.
Parameters
eventInfo : EventInfoAn object containing information about the fired event.