Watchdog (watchdog)
@ckeditor/ckeditor5-watchdog/src/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.
Filtering
Properties
-
crashes : Array.<Object>
module:watchdog/watchdog~Watchdog#crashes
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
,
-
state : 'initializing' | 'ready' | 'crashed' | 'crashedPermanently' | 'destroyed'
module:watchdog/watchdog~Watchdog#state
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 toinitializing
orcrashedPermanently
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 callingwatchdog.destroy()
.
-
_crashNumberLimit : Number
module:watchdog/watchdog~Watchdog#_crashNumberLimit
protected
Related:
-
_creator : function
module:watchdog/watchdog~Watchdog#_creator
protected
The creation method.
Related:
-
_destructor : function
module:watchdog/watchdog~Watchdog#_destructor
protected
The destruction method.
Related:
-
_item : Object | undefined
module:watchdog/watchdog~Watchdog#_item
protected
The watched item.
-
_minimumNonErrorTimePeriod : Number
module:watchdog/watchdog~Watchdog#_minimumNonErrorTimePeriod
protected
Related:
-
_now
module:watchdog/watchdog~Watchdog#_now
protected
Returns 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. -
_listeners : Object.<String, Function>>
module:watchdog/watchdog~Watchdog#_listeners
private
A dictionary of event emitter listeners.
Methods
-
constructor( config )
module:watchdog/watchdog~Watchdog#constructor
Parameters
config : WatchdogConfig
The watchdog plugin configuration.
-
destroy()
module:watchdog/watchdog~Watchdog#destroy
Destroys the watchdog and releases the resources.
-
off( eventName, callback )
module:watchdog/watchdog~Watchdog#off
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 : String
The event name.
callback : function
A callback which will be removed from event listeners.
-
on( eventName, callback )
module:watchdog/watchdog~Watchdog#on
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.Parameters
eventName : String
The event name.
callback : function
A callback which will be added to event listeners.
-
setCreator( creator )
module:watchdog/watchdog~Watchdog#setCreator
Sets the function that is responsible for creating watched items.
Parameters
creator : function
A callback responsible for creating an item. Returns a promise that is resolved when the item is created.
-
setDestructor( destructor )
module:watchdog/watchdog~Watchdog#setDestructor
Sets the function that is responsible for destroying watched items.
Parameters
destructor : function
A callback that takes the item and returns the promise to the destroying process.
-
_fire( eventName, args )
module:watchdog/watchdog~Watchdog#_fire
protected
Fires an event with a given event name and arguments.
Note that this method differs from the CKEditor 5's default
EventEmitterMixin
implementation.Parameters
eventName : String
The event name.
args : *
Event arguments.
-
_isErrorComingFromThisItem( error )
module:watchdog/watchdog~Watchdog#_isErrorComingFromThisItem
protected
Traverses the error context and the watched item to find out whether the error should be handled by the given item.
Parameters
error : CKEditorError
-
_restart()
module:watchdog/watchdog~Watchdog#_restart
protected
The method responsible for restarting the watched item.
-
_startErrorHandling()
module:watchdog/watchdog~Watchdog#_startErrorHandling
protected
Starts error handling by attaching global error handlers.
-
_stopErrorHandling()
module:watchdog/watchdog~Watchdog#_stopErrorHandling
protected
Stops error handling by detaching global error handlers.
-
_boundErrorHandler()
module:watchdog/watchdog~Watchdog#_boundErrorHandler
private
Checks if the event error comes from the underlying item and restarts the item.
-
_handleError( error, evt )
module:watchdog/watchdog~Watchdog#_handleError
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.
Fires
-
_shouldReactToError( error )
module:watchdog/watchdog~Watchdog#_shouldReactToError
private
Checks whether an error should be handled by the watchdog.
Parameters
error : Error
An error that was caught by the error handling process.
-
_shouldRestart()
module:watchdog/watchdog~Watchdog#_shouldRestart
private
Checks if the watchdog should restart the underlying item.
Events
-
error( eventInfo )
module:watchdog/watchdog~Watchdog#event:error
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.' ); } );
Parameters
eventInfo : EventInfo
An object containing information about the fired event.
Every day, we work hard to keep our documentation complete. Have you spotted an outdated information? Is something missing? Please report it via our issue tracker.