瀏覽代碼

Improved error rethrowing.

Maciej Bukowski 6 年之前
父節點
當前提交
17486c297b

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

@@ -1,5 +1,3 @@
-/* globals console */
-
 /**
  * @license Copyright (c) 2003-2019, CKSource - Frederico Knabben. All rights reserved.
  * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
@@ -109,8 +107,8 @@ export default class CKEditorError extends Error {
 		}
 
 		/**
-		 * An unexpected error occurred inside the CKEditor 5 codebase. The `error.data.originalError` property
-		 * shows the original error properties.
+		 * An unexpected error occurred inside the CKEditor 5 codebase. This error will look like the original one
+		 * to make the debugging easier.
 		 *
 		 * This error is only useful when the editor is initialized using the {@link module:watchdog/watchdog~Watchdog} feature.
 		 * In case of such error (or any {@link module:utils/ckeditorerror~CKEditorError} error) the watchdog should restart the editor.
@@ -120,12 +118,9 @@ export default class CKEditorError extends Error {
 		const error = new CKEditorError( err.message, context );
 
 		// Restore the original stack trace to make the error look like the original one.
+		// See https://github.com/ckeditor/ckeditor5/issues/5595 for more details.
 		error.stack = err.stack;
 
-		console.log( err.stack );
-
-		console.log( err );
-
 		throw error;
 	}
 }

+ 1 - 0
packages/ckeditor5-utils/src/emittermixin.js

@@ -239,6 +239,7 @@ const EmitterMixin = {
 
 			return eventInfo.return;
 		} catch ( err ) {
+			// @if CK_DEBUG // throw err;
 			CKEditorError.rethrowUnexpectedError( err, this );
 		}
 	},

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

@@ -106,13 +106,7 @@ describe( 'CKEditorError', () => {
 
 			expectToThrowCKEditorError( () => {
 				CKEditorError.rethrowUnexpectedError( error, context );
-			}, /unexpected-error/, context, {
-				originalError: {
-					message: 'foo',
-					stack: 'bar',
-					name: 'Error'
-				}
-			} );
+			}, /foo/, context );
 		} );
 	} );
 } );

+ 1 - 1
packages/ckeditor5-utils/tests/emittermixin.js

@@ -176,7 +176,7 @@ describe( 'EmitterMixin', () => {
 
 			expectToThrowCKEditorError( () => {
 				emitter.fire( 'test' );
-			}, /bar/ );
+			}, /foo/ );
 		} );
 
 		describe( 'return value', () => {