瀏覽代碼

Docs: Improved error docs.

Szymon Cofalik 7 年之前
父節點
當前提交
32a2f1e549

+ 15 - 1
packages/ckeditor5-engine/src/model/selection.js

@@ -431,7 +431,21 @@ export default class Selection {
 		// Check whether there is any range in new ranges set that is different than all already added ranges.
 		const anyNewRange = newRanges.some( newRange => {
 			if ( !( newRange instanceof Range ) ) {
-				throw new CKEditorError( 'model-selection-added-not-range: Trying to add an object that is not an instance of Range.' );
+				/**
+				 * Selection range set to an object that is not an instance of {@link module:engine/model/range~Range}.
+				 *
+				 * Only {@link module:engine/model/range~Range} instances can be used to set a selection.
+				 * Common mistakes leading to this error are:
+				 *
+				 * * using DOM `Range` object,
+				 * * incorrect CKEditor 5 installation with multiple `ckeditor5-engine` packages having different versions.
+				 *
+				 * @error model-selection-set-ranges-not-range
+				 */
+				throw new CKEditorError(
+					'model-selection-set-ranges-not-range: ' +
+					'Selection range set to an object that is not an instance of model.Range.'
+				);
 			}
 
 			return this._ranges.every( oldRange => {

+ 9 - 1
packages/ckeditor5-engine/src/view/selection.js

@@ -643,7 +643,15 @@ export default class Selection {
 	 */
 	_addRange( range, isBackward = false ) {
 		if ( !( range instanceof Range ) ) {
-			throw new CKEditorError( 'view-selection-invalid-range: Invalid Range.' );
+			/**
+			 * Selection range set to an object that is not an instance of {@link module:engine/view/range~Range}.
+			 *
+			 * @error view-selection-add-range-not-range
+			 */
+			throw new CKEditorError(
+				'view-selection-add-range-not-range: ' +
+				'Selection range set to an object that is not an instance of view.Range'
+			);
 		}
 
 		this._pushRange( range );

+ 1 - 1
packages/ckeditor5-engine/tests/model/documentselection.js

@@ -334,7 +334,7 @@ describe( 'DocumentSelection', () => {
 		it( 'should throw an error when range is invalid', () => {
 			expect( () => {
 				selection._setTo( [ { invalid: 'range' } ] );
-			} ).to.throw( CKEditorError, /model-selection-added-not-range/ );
+			} ).to.throw( CKEditorError, /model-selection-set-ranges-not-range/ );
 		} );
 
 		it( 'should log a warning when trying to set selection to the graveyard', () => {

+ 1 - 1
packages/ckeditor5-engine/tests/model/selection.js

@@ -633,7 +633,7 @@ describe( 'Selection', () => {
 		it( 'should throw an error when range is invalid', () => {
 			expect( () => {
 				selection._setRanges( [ { invalid: 'range' } ] );
-			} ).to.throw( CKEditorError, /model-selection-added-not-range/ );
+			} ).to.throw( CKEditorError, /model-selection-set-ranges-not-range/ );
 		} );
 
 		it( 'should remove all ranges and add given ranges', () => {

+ 2 - 2
packages/ckeditor5-engine/tests/view/documentselection.js

@@ -113,7 +113,7 @@ describe( 'DocumentSelection', () => {
 			expect( () => {
 				// eslint-disable-next-line no-new
 				new DocumentSelection( [ { invalid: 'range' } ] );
-			} ).to.throw( CKEditorError, 'view-selection-invalid-range: Invalid Range.' );
+			} ).to.throw( CKEditorError, /view-selection-add-range-not-range/ );
 		} );
 
 		it( 'should throw an error when ranges intersects', () => {
@@ -1004,7 +1004,7 @@ describe( 'DocumentSelection', () => {
 			it( 'should throw an error when range is invalid', () => {
 				expect( () => {
 					documentSelection._setTo( [ { invalid: 'range' } ] );
-				} ).to.throw( CKEditorError, 'view-selection-invalid-range: Invalid Range.' );
+				} ).to.throw( CKEditorError, /view-selection-add-range-not-range/ );
 			} );
 
 			it( 'should throw when range is intersecting with already added range', () => {

+ 2 - 2
packages/ckeditor5-engine/tests/view/selection.js

@@ -113,7 +113,7 @@ describe( 'Selection', () => {
 			expect( () => {
 				// eslint-disable-next-line no-new
 				new Selection( [ { invalid: 'range' } ] );
-			} ).to.throw( CKEditorError, 'view-selection-invalid-range: Invalid Range.' );
+			} ).to.throw( CKEditorError, /view-selection-add-range-not-range/ );
 		} );
 
 		it( 'should throw an error when ranges intersects', () => {
@@ -878,7 +878,7 @@ describe( 'Selection', () => {
 			it( 'should throw an error when range is invalid', () => {
 				expect( () => {
 					selection.setTo( [ { invalid: 'range' } ] );
-				} ).to.throw( CKEditorError, 'view-selection-invalid-range: Invalid Range.' );
+				} ).to.throw( CKEditorError, /view-selection-add-range-not-range/ );
 			} );
 
 			it( 'should throw when range is intersecting with already added range', () => {