Skip to content
This repository has been archived by the owner on Jun 26, 2020. It is now read-only.

Introduce Watchdog #2

Merged
merged 52 commits into from
Jul 2, 2019
Merged
Changes from 1 commit
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
49373ed
Added initial implementation of Watchdog.
ma2ciek Jun 18, 2019
d194458
Added package.json and LICENSE.md files
ma2ciek Jun 18, 2019
37d3cd7
Added missing files.
ma2ciek Jun 18, 2019
8aac285
Aligned readme to readmes in other packages.
ma2ciek Jun 18, 2019
34740c0
Added simple test.
ma2ciek Jun 19, 2019
e7a4551
Added test for restarting the editor.
ma2ciek Jun 19, 2019
faf1c81
Added simple tests for error handling.
ma2ciek Jun 20, 2019
d557600
Added advanced error handling tests.
ma2ciek Jun 21, 2019
333b75c
Added more error handling tests.
ma2ciek Jun 21, 2019
5fb503f
Fixed saved event error name.
ma2ciek Jun 21, 2019
9e38691
Fixed tests destruction, added test for missin context warning.
ma2ciek Jun 21, 2019
1c8cd31
Improved tests, fixed small error in the Watchdog.
ma2ciek Jun 21, 2019
10ccc87
Made CC 100%.
ma2ciek Jun 21, 2019
1076ff7
Fixed lint issues.
ma2ciek Jun 21, 2019
8c64768
Improved restoring component if editor.getData() throws an error.
ma2ciek Jun 21, 2019
fe9e766
Fixed code comment.
ma2ciek Jun 21, 2019
6130639
Fixed test.
ma2ciek Jun 21, 2019
8d7c54d
Simplified tests.
ma2ciek Jun 21, 2019
0d223c4
Fixed `shouldNodeBeSkipped` - added support for symbols and iterable …
ma2ciek Jun 21, 2019
4be82e0
Improved API docs.
ma2ciek Jun 23, 2019
127c96a
Added support for `Watchdog.for()`.
ma2ciek Jun 24, 2019
61463b3
Fixed naming.
ma2ciek Jun 24, 2019
a058a59
Fixed timers in tests.
ma2ciek Jun 24, 2019
db19e62
Fixed naming.
ma2ciek Jun 24, 2019
f1b13f8
Fixed API docs.
ma2ciek Jun 24, 2019
feec3f3
Added support for other Editor signatures. Changed ctx to context.
ma2ciek Jun 24, 2019
c691619
Added manual test.
ma2ciek Jun 24, 2019
a4bb99d
Added missing test.
ma2ciek Jun 24, 2019
4849273
Improved test description.
ma2ciek Jun 24, 2019
2314613
Added support for `null` context. Improved API docs.
ma2ciek Jun 24, 2019
9cad5a3
Moved tree traversing to the util, aligned tests to changes in Classi…
ma2ciek Jun 24, 2019
c4020e7
API docs improvements.
ma2ciek Jun 25, 2019
db3f04d
API docs improvements.
ma2ciek Jun 25, 2019
8688447
Improved API docs.
ma2ciek Jun 25, 2019
2935eff
WIP - docs.
ma2ciek Jun 27, 2019
b6d85e5
Aligned testing CKEditor errors.
ma2ciek Jun 27, 2019
6bf8dfd
Fixed incorrect API usage.
ma2ciek Jul 1, 2019
b598495
Apply suggestions from code review
ma2ciek Jul 1, 2019
ab04623
Added deep copying editor config.
ma2ciek Jul 1, 2019
c32679a
Merge branch 't/1' of github.com:ckeditor/ckeditor5-watchdog into t/1
ma2ciek Jul 1, 2019
6f4c6a7
Swap `restart()` and `create()` methods.
ma2ciek Jul 1, 2019
7c59f27
Improved API docs.
ma2ciek Jul 1, 2019
35e3594
Improved API docs.
ma2ciek Jul 1, 2019
163acd5
Improved description.
ma2ciek Jul 1, 2019
b76e8b2
Added API docs.
ma2ciek Jul 1, 2019
ebe00c1
Fixed 100CC.
ma2ciek Jul 1, 2019
b02b1d1
Small fixes.
Jul 1, 2019
8958425
Update docs.
Jul 1, 2019
0be0b73
Update docs.
Jul 1, 2019
08aaca9
Make `config` parameter optional.
Jul 1, 2019
c1436b8
Fixed API docs.
ma2ciek Jul 2, 2019
deebaa4
Fixed the document version comparison.
ma2ciek Jul 2, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Added support for null context. Improved API docs.
ma2ciek committed Jun 24, 2019
commit 2314613e0cb615fe92e52ad04779191344499657
20 changes: 19 additions & 1 deletion src/watchdog.js
Original file line number Diff line number Diff line change
@@ -36,6 +36,18 @@ import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
* watchdog.setDestructor( editor => editor.destroy() );
*
* watchdog.create( elementOrData, editorConfig ).then( editor => {} );
*
* Other important APIs:
*
* watchdog.on( 'crash', () => { console.log( 'Editor crashed.' ) } );
ma2ciek marked this conversation as resolved.
Show resolved Hide resolved
* watchdog.on( 'restart', () => { console.log( 'Editor was restarted.' ) } );
*
* watchdog.restart(); // Restarts the editor.
* watchdog.destroy(); // Destroys the editor and global error event listeners.
*
* watchdog.editor; // Current editor instance.
*
* watchdog.crashes.forEach( crashInfo => console.log( crashInfo ) );
*/
export default class Watchdog {
/**
@@ -308,12 +320,17 @@ export default class Watchdog {
return;
}

if ( !event.error.context ) {
if ( event.error.context === undefined ) {
console.error( 'The error is missing its context and Watchdog cannot restart the proper editor.' );

return;
}

// In some cases the editor should not be restarted - e.g. in case of the editor initialization.
if ( event.error.context === null ) {
return;
}

if ( this._isErrorComingFromThisEditor( event.error ) ) {
this.crashes.push( {
message: event.error.message,
@@ -352,6 +369,7 @@ export default class Watchdog {
*/
static for( Editor ) {
const watchdog = new Watchdog();

watchdog.setCreator( ( elementOrData, config ) => Editor.create( elementOrData, config ) );
watchdog.setDestructor( editor => editor.destroy() );

28 changes: 28 additions & 0 deletions tests/watchdog.js
Original file line number Diff line number Diff line change
@@ -481,6 +481,34 @@ describe( 'Watchdog', () => {
} );
} );

it( 'Watchdog should omit error if the CKEditorError context is equal to null', () => {
const watchdog = new Watchdog();

watchdog.setCreator( ( el, config ) => FakeEditor.create( el, config ) );
watchdog.setDestructor( editor => editor.destroy() );

// sinon.stub( window, 'onerror' ).value( undefined ); and similar do not work.
const originalErrorHandler = window.onerror;
window.onerror = undefined;

sinon.stub( console, 'error' );

return watchdog.create( document.createElement( 'div' ) ).then( () => {
setTimeout( () => throwCKEditorError( 'foo', null ) );

return new Promise( res => {
setTimeout( () => {
window.onerror = originalErrorHandler;

expect( watchdog.crashes ).to.deep.equal( [] );
sinon.assert.notCalled( console.error );

watchdog.destroy().then( res );
} );
} );
} );
} );

it( 'editor should be restarted with the data before the crash #1', () => {
const watchdog = new Watchdog();