Skip to content
This repository has been archived by the owner on Jun 26, 2020. It is now read-only.

Commit

Permalink
Merge bea61e2 into 5ec2518
Browse files Browse the repository at this point in the history
  • Loading branch information
ma2ciek committed Nov 21, 2019
2 parents 5ec2518 + bea61e2 commit c72be9e
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 27 deletions.
24 changes: 12 additions & 12 deletions src/ckeditorerror.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,11 @@ export default class CKEditorError extends Error {

/**
* A utility that ensures the the thrown error is a {@link module:utils/ckeditorerror~CKEditorError} one.
* It is uesful when combined with the {@link module:watchdog/watchdog~Watchdog} feature, which can restart the editor in case
* It is useful when combined with the {@link module:watchdog/watchdog~Watchdog} feature, which can restart the editor in case
* of a {@link module:utils/ckeditorerror~CKEditorError} error.
*
* @param {Error} err An error.
* @param {Object} context An object conected through properties with the editor instance. This context will be used
* @param {Object} context An object connected through properties with the editor instance. This context will be used
* by the watchdog to verify which editor should be restarted.
*/
static rethrowUnexpectedError( err, context ) {
Expand All @@ -107,21 +107,21 @@ 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 wathcdog should restart the editor.
* In case of such error (or any {@link module:utils/ckeditorerror~CKEditorError} error) the watchdog should restart the editor.
*
* @error unexpected-error
*/
throw new CKEditorError( 'unexpected-error', context, {
originalError: {
message: err.message,
stack: err.stack,
name: err.name
}
} );
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;

throw error;
}
}

Expand Down
1 change: 1 addition & 0 deletions src/emittermixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ const EmitterMixin = {

return eventInfo.return;
} catch ( err ) {
// @if CK_DEBUG // throw err;
CKEditorError.rethrowUnexpectedError( err, this );
}
},
Expand Down
8 changes: 1 addition & 7 deletions tests/ckeditorerror.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,7 @@ describe( 'CKEditorError', () => {

expectToThrowCKEditorError( () => {
CKEditorError.rethrowUnexpectedError( error, context );
}, /unexpected-error/, context, {
originalError: {
message: 'foo',
stack: 'bar',
name: 'Error'
}
} );
}, /foo/, context );
} );
} );
} );
10 changes: 2 additions & 8 deletions tests/emittermixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ describe( 'EmitterMixin', () => {
} );

it( 'should wrap an error into the CKEditorError if a native error was thrown', () => {
const error = new Error( 'foo' );
const error = new TypeError( 'foo' );
error.stack = 'bar';

emitter.on( 'test', () => {
Expand All @@ -176,13 +176,7 @@ describe( 'EmitterMixin', () => {

expectToThrowCKEditorError( () => {
emitter.fire( 'test' );
}, /unexpected-error/, emitter, {
originalError: {
message: 'foo',
stack: 'bar',
name: 'Error'
}
} );
}, /foo/ );
} );

describe( 'return value', () => {
Expand Down

0 comments on commit c72be9e

Please sign in to comment.