diff --git a/src/model/selection.js b/src/model/selection.js index 4a2bf2c29..8e1c989ac 100644 --- a/src/model/selection.js +++ b/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 => { diff --git a/src/view/selection.js b/src/view/selection.js index bd132dac8..e8b00e75a 100644 --- a/src/view/selection.js +++ b/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 ); diff --git a/tests/model/documentselection.js b/tests/model/documentselection.js index 8a5a89852..299b06913 100644 --- a/tests/model/documentselection.js +++ b/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', () => { diff --git a/tests/model/selection.js b/tests/model/selection.js index 4439e9012..630420c5c 100644 --- a/tests/model/selection.js +++ b/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', () => { diff --git a/tests/view/documentselection.js b/tests/view/documentselection.js index 4525b544e..78ca8a11d 100644 --- a/tests/view/documentselection.js +++ b/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', () => { diff --git a/tests/view/selection.js b/tests/view/selection.js index 910f20123..6c503e9d1 100644 --- a/tests/view/selection.js +++ b/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', () => {