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

Rethrow original error in try-catch blocks when the debug=true mode is on #1810

Merged
merged 2 commits into from
Nov 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/model/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,8 @@ export default class Model {
return callback( this._currentWriter );
}
} catch ( err ) {
// @if CK_DEBUG // throw err;
/* istanbul ignore next */
CKEditorError.rethrowUnexpectedError( err, this );
}
}
Expand Down Expand Up @@ -224,6 +226,8 @@ export default class Model {
this._runPendingChanges();
}
} catch ( err ) {
// @if CK_DEBUG // throw err;
/* istanbul ignore next */
CKEditorError.rethrowUnexpectedError( err, this );
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/view/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,8 @@ export default class View {

return callbackResult;
} catch ( err ) {
// @if CK_DEBUG // throw err;
/* istanbul ignore next */
CKEditorError.rethrowUnexpectedError( err, this );
}
}
Expand Down
26 changes: 6 additions & 20 deletions tests/model/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -324,21 +324,14 @@ describe( 'Model', () => {
} );
} );

it( 'should catch a non-ckeditor error inside the `change()` block and throw the CKEditorError error outside of it', () => {
it( 'should rethrow native errors as they are in the dubug=true mode in the model.change() block', () => {
const error = new TypeError( 'foo' );
error.stack = 'bar';

expectToThrowCKEditorError( () => {
expect( () => {
model.change( () => {
throw error;
} );
}, /unexpected-error/, model, {
originalError: {
message: 'foo',
stack: 'bar',
name: 'TypeError'
}
} );
} ).to.throw( TypeError, /foo/ );
} );

it( 'should throw the original CKEditorError error if it was thrown inside the `change()` block', () => {
Expand All @@ -349,21 +342,14 @@ describe( 'Model', () => {
}, /foo/, null, { foo: 1 } );
} );

it( 'should catch a non-ckeditor error inside the `enqueueChange()` block and throw the CKEditorError error outside of it', () => {
it( 'should rethrow native errors as they are in the dubug=true mode in the enqueueChange() block', () => {
const error = new TypeError( 'foo' );
error.stack = 'bar';

expectToThrowCKEditorError( () => {
expect( () => {
model.enqueueChange( () => {
throw error;
} );
}, /unexpected-error/, model, {
originalError: {
message: 'foo',
stack: 'bar',
name: 'TypeError'
}
} );
} ).to.throw( TypeError, /foo/ );
} );

it( 'should throw the original CKEditorError error if it was thrown inside the `enqueueChange()` block', () => {
Expand Down
13 changes: 3 additions & 10 deletions tests/view/view/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -804,21 +804,14 @@ describe( 'view', () => {
expect( result3 ).to.undefined;
} );

it( 'should catch native errors and wrap them into the CKEditorError errors', () => {
it( 'should rethrow native errors as they are in the dubug=true mode', () => {
const error = new TypeError( 'foo' );
error.stack = 'bar';

expectToThrowCKEditorError( () => {
expect( () => {
view.change( () => {
throw error;
} );
}, /unexpected-error/, view, {
originalError: {
message: 'foo',
stack: 'bar',
name: 'TypeError'
}
} );
} ).to.throw( TypeError, /foo/ );
} );

it( 'should rethrow custom CKEditorError errors', () => {
Expand Down