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

Commit

Permalink
Rethrown original error in try-catch blocks when the debug=true mod…
Browse files Browse the repository at this point in the history
…e is on.
  • Loading branch information
ma2ciek committed Nov 21, 2019
1 parent 5e4c92a commit 1de4b5a
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 30 deletions.
2 changes: 2 additions & 0 deletions src/model/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ export default class Model {
return callback( this._currentWriter );
}
} catch ( err ) {
// @if CK_DEBUG // throw err;
CKEditorError.rethrowUnexpectedError( err, this );
}
}
Expand Down Expand Up @@ -224,6 +225,7 @@ export default class Model {
this._runPendingChanges();
}
} catch ( err ) {
// @if CK_DEBUG // throw err;
CKEditorError.rethrowUnexpectedError( err, this );
}
}
Expand Down
1 change: 1 addition & 0 deletions src/view/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,7 @@ export default class View {

return callbackResult;
} catch ( err ) {
// @if CK_DEBUG // throw err;
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

0 comments on commit 1de4b5a

Please sign in to comment.