8
0
فهرست منبع

Converted Collection's errors to CKEditorError (I left the one in get() as we're planning to remove it).

Piotrek Koszuliński 10 سال پیش
والد
کامیت
85ca0078a1
2فایلهای تغییر یافته به همراه19 افزوده شده و 5 حذف شده
  1. 13 3
      packages/ckeditor5-engine/src/collection.js
  2. 6 2
      packages/ckeditor5-engine/tests/mvc/collection/collection.js

+ 13 - 3
packages/ckeditor5-engine/src/collection.js

@@ -14,7 +14,7 @@
  * @mixins EventEmitter
  */
 
-CKEDITOR.define( [ 'emittermixin', 'utils' ], function( EmitterMixin, utils ) {
+CKEDITOR.define( [ 'emittermixin', 'ckeditorerror', 'utils' ], function( EmitterMixin, CKEditorError, utils ) {
 	class Collection {
 		/**
 		 * Creates a new Collection instance.
@@ -82,14 +82,24 @@ CKEDITOR.define( [ 'emittermixin', 'utils' ], function( EmitterMixin, utils ) {
 				modelOrIndex = this._models.indexOf( modelOrIndex );
 
 				if ( modelOrIndex == -1 ) {
-					throw new Error( 'Model not found' );
+					/**
+					 * Model not found.
+					 *
+					 * @error collection-model-404
+					 */
+					throw new CKEditorError( 'collection-model-404: Model not found.' );
 				}
 			}
 
 			var removedModel = this._models.splice( modelOrIndex, 1 )[ 0 ];
 
 			if ( !removedModel ) {
-				throw new Error( 'Index not found' );
+				/**
+				 * Index not found.
+				 *
+				 * @error collection-index-404
+				 */
+				throw new CKEditorError( 'collection-index-404: Index not found.' );
 			}
 
 			this.fire( 'remove', removedModel );

+ 6 - 2
packages/ckeditor5-engine/tests/mvc/collection/collection.js

@@ -94,21 +94,25 @@ describe( 'remove', function() {
 	} );
 
 	it( 'should throw an error on invalid index', function() {
+		var CKEditorError = modules.ckeditorerror;
+
 		var box = getCollection();
 		box.add( getItem() );
 
 		expect( function() {
 			box.remove( 1 );
-		} ).to.throw( Error, 'Index not found' );
+		} ).to.throw( CKEditorError, /^collection-index-404/ );
 	} );
 
 	it( 'should throw an error on invalid model', function() {
+		var CKEditorError = modules.ckeditorerror;
+
 		var box = getCollection();
 		box.add( getItem() );
 
 		expect( function() {
 			box.remove( getItem() );
-		} ).to.throw( Error, 'Model not found' );
+		} ).to.throw( CKEditorError, /^collection-model-404/ );
 	} );
 } );