Sfoglia il codice sorgente

Added support for the null as a context.

Maciej Bukowski 6 anni fa
parent
commit
0308aa09c3

+ 4 - 3
packages/ckeditor5-utils/src/ckeditorerror.js

@@ -32,8 +32,9 @@ export default class CKEditorError extends Error {
 	 * @param {String} message The error message in an `error-name: Error message.` format.
 	 * During the minification process the "Error message" part will be removed to limit the code size
 	 * and a link to this error documentation will be added to the `message`.
-	 * @param {Object} context A context of the error by which the {@link module:watchdog/watchdog~Watchdog watchdog}
-	 * is able to determine which editor crashed. It should be an editor instance or a property connected to it.
+	 * @param {Object|null} context A context of the error by which the {@link module:watchdog/watchdog~Watchdog watchdog}
+	 * is able to determine which editor crashed. It should be an editor instance or a property connected to it. It can be also
+	 * a `null` value if the editor should not be restarted in case of the error (e.g. during the editor initialization).
 	 * @param {Object} [data] Additional data describing the error. A stringified version of this object
 	 * will be appended to the error message, so the data are quickly visible in the console. The original
 	 * data object will also be later available under the {@link #data} property.
@@ -55,7 +56,7 @@ export default class CKEditorError extends Error {
 		/**
 		 * A context of the error by which the Watchdog is able to determine which editor crashed.
 		 *
-		 * @type {Object}
+		 * @type {Object|null}
 		 */
 		this.context = context;
 

+ 7 - 7
packages/ckeditor5-utils/tests/ckeditorerror.js

@@ -14,13 +14,13 @@ describe( 'CKEditorError', () => {
 	} );
 
 	it( 'sets the name', () => {
-		const error = new CKEditorError( 'foo', {} );
+		const error = new CKEditorError( 'foo', null );
 
 		expect( error ).to.have.property( 'name', 'CKEditorError' );
 	} );
 
 	it( 'sets the message', () => {
-		const error = new CKEditorError( 'foo', {} );
+		const error = new CKEditorError( 'foo', null );
 
 		expect( error ).to.have.property( 'message', 'foo' );
 		expect( error.data ).to.be.undefined;
@@ -28,7 +28,7 @@ describe( 'CKEditorError', () => {
 
 	it( 'sets the message and data', () => {
 		const data = { bar: 1 };
-		const error = new CKEditorError( 'foo', {}, data );
+		const error = new CKEditorError( 'foo', null, data );
 
 		expect( error ).to.have.property( 'message', 'foo {"bar":1}' );
 		expect( error ).to.have.property( 'data', data );
@@ -54,14 +54,14 @@ describe( 'CKEditorError', () => {
 			bom: new Foo(),
 			bim: 10
 		};
-		const error = new CKEditorError( 'foo', {}, data );
+		const error = new CKEditorError( 'foo', null, data );
 
 		expect( error ).to.have.property( 'message', 'foo {"bar":"a","bom":{"x":1},"bim":10}' );
 		expect( error ).to.have.property( 'data', data );
 	} );
 
 	it( 'contains a link which leads to the documentation', () => {
-		const error = new CKEditorError( 'model-schema-no-item: Specified item cannot be found.', {} );
+		const error = new CKEditorError( 'model-schema-no-item: Specified item cannot be found.', null );
 
 		const errorMessage = 'model-schema-no-item: Specified item cannot be found. ' +
 			`Read more: ${ DOCUMENTATION_URL }#error-model-schema-no-item\n`;
@@ -70,7 +70,7 @@ describe( 'CKEditorError', () => {
 	} );
 
 	it( 'link to documentation is added before the additional data message', () => {
-		const error = new CKEditorError( 'model-schema-no-item: Specified item cannot be found.', {}, { foo: 1, bar: 2 } );
+		const error = new CKEditorError( 'model-schema-no-item: Specified item cannot be found.', null, { foo: 1, bar: 2 } );
 
 		const errorMessage = 'model-schema-no-item: Specified item cannot be found. ' +
 			`Read more: ${ DOCUMENTATION_URL }#error-model-schema-no-item\n ` +
@@ -81,7 +81,7 @@ describe( 'CKEditorError', () => {
 
 	describe( 'is()', () => {
 		it( 'checks if error is an instance of CKEditorError', () => {
-			const ckeditorError = new CKEditorError( 'foo', {} );
+			const ckeditorError = new CKEditorError( 'foo', null );
 			const regularError = new Error( 'foo' );
 
 			expect( ( !!ckeditorError.is && ckeditorError.is( 'CKEditorError' ) ) ).to.be.true;