Ver código fonte

Fixed error handling to throw Error instances instead of strings.

fredck 10 anos atrás
pai
commit
dbbc58c3ae

+ 3 - 3
packages/ckeditor5-utils/src/mvc/collection.js

@@ -68,7 +68,7 @@ CKEDITOR.define( [ 'emitter', 'utils' ], function( EmitterMixin, utils ) {
 			var model = this._models[ index ];
 
 			if ( !model ) {
-				throw 'Index not found';
+				throw new Error( 'Index not found' );
 			}
 
 			return model;
@@ -86,14 +86,14 @@ CKEDITOR.define( [ 'emitter', 'utils' ], function( EmitterMixin, utils ) {
 				modelOrIndex = this._models.indexOf( modelOrIndex );
 
 				if ( modelOrIndex == -1 ) {
-					throw 'Model not found';
+					throw new Error( 'Model not found' );
 				}
 			}
 
 			var removedModel = this._models.splice( modelOrIndex, 1 )[ 0 ];
 
 			if ( !removedModel ) {
-				throw 'Index not found';
+				throw new Error( 'Index not found' );
 			}
 
 			this.fire( 'remove', removedModel );

+ 3 - 3
packages/ckeditor5-utils/tests/mvc/collection/collection.js

@@ -44,7 +44,7 @@ describe( 'get', function() {
 
 		expect( function() {
 			box.get( 1 );
-		} ).to.throw( 'Index not found' );
+		} ).to.throw( Error, 'Index not found' );
 	} );
 } );
 
@@ -101,7 +101,7 @@ describe( 'remove', function() {
 
 		expect( function() {
 			box.remove( 1 );
-		} ).to.throw( 'Index not found' );
+		} ).to.throw( Error, 'Index not found' );
 	} );
 
 	it( 'should throw error on invalid model', function() {
@@ -110,7 +110,7 @@ describe( 'remove', function() {
 
 		expect( function() {
 			box.remove( getItem() );
-		} ).to.throw( 'Model not found' );
+		} ).to.throw( Error, 'Model not found' );
 	} );
 } );