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

Commit

Permalink
Merge branch t/ckeditor5-watchdog/1
Browse files Browse the repository at this point in the history
Internal: Add context to CKEditorError exceptions. Required by ckeditor/ckeditor5-watchdog#2.
  • Loading branch information
Piotr Jasiun committed Jul 2, 2019
2 parents 6d061dd + cd61e9b commit 4fee7c3
Show file tree
Hide file tree
Showing 11 changed files with 91 additions and 63 deletions.
8 changes: 6 additions & 2 deletions src/componentfactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@ export default class ComponentFactory {
* @param {String} name The name of the component.
*/
throw new CKEditorError(
'componentfactory-item-exists: The item already exists in the component factory.', { name }
'componentfactory-item-exists: The item already exists in the component factory.',
this,
{ name }
);
}

Expand Down Expand Up @@ -113,7 +115,9 @@ export default class ComponentFactory {
* @param {String} name The name of the missing component.
*/
throw new CKEditorError(
'componentfactory-item-missing: The required component is not registered in the factory.', { name }
'componentfactory-item-missing: The required component is not registered in the factory.',
this,
{ name }
);
}

Expand Down
15 changes: 12 additions & 3 deletions src/panel/balloon/contextualballoon.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,10 @@ export default class ContextualBalloon extends Plugin {
*
* @error contextualballoon-add-view-exist
*/
throw new CKEditorError( 'contextualballoon-add-view-exist: Cannot add configuration of the same view twice.' );
throw new CKEditorError(
'contextualballoon-add-view-exist: Cannot add configuration of the same view twice.',
[ this, data ]
);
}

const stackId = data.stackId || 'main';
Expand Down Expand Up @@ -248,7 +251,10 @@ export default class ContextualBalloon extends Plugin {
*
* @error contextualballoon-remove-view-not-exist
*/
throw new CKEditorError( 'contextualballoon-remove-view-not-exist: Cannot remove the configuration of a non-existent view.' );
throw new CKEditorError(
'contextualballoon-remove-view-not-exist: Cannot remove the configuration of a non-existent view.',
[ this, view ]
);
}

const stack = this._viewToStack.get( view );
Expand Down Expand Up @@ -313,7 +319,10 @@ export default class ContextualBalloon extends Plugin {
*
* @error contextualballoon-showstack-stack-not-exist
*/
throw new CKEditorError( 'contextualballoon-showstack-stack-not-exist: Cannot show a stack that does not exist.' );
throw new CKEditorError(
'contextualballoon-showstack-stack-not-exist: Cannot show a stack that does not exist.',
this
);
}

if ( this._visibleStack === stack ) {
Expand Down
12 changes: 9 additions & 3 deletions src/template.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,10 @@ export default class Template {
*
* @error ui-template-revert-not-applied
*/
throw new CKEditorError( 'ui-template-revert-not-applied: Attempting to revert a template which has not been applied yet.' );
throw new CKEditorError(
'ui-template-revert-not-applied: Attempting to revert a template which has not been applied yet.',
[ this, node ]
);
}

this._revertTemplateFromNode( node, this._revertData );
Expand Down Expand Up @@ -409,7 +412,8 @@ export default class Template {
* @error ui-template-wrong-syntax
*/
throw new CKEditorError(
'ui-template-wrong-syntax: Node definition must have either "tag" or "text" when rendering a new Node.'
'ui-template-wrong-syntax: Node definition must have either "tag" or "text" when rendering a new Node.',
this
);
}

Expand Down Expand Up @@ -1356,6 +1360,7 @@ function extendObjectValueArray( obj, ext ) {
//
// @param {module:ui/template~Template} def A template instance to be extended.
// @param {module:ui/template~TemplateDefinition} def A definition which is to extend the template instance.
// @param {Object} Error context.
function extendTemplate( template, def ) {
if ( def.attributes ) {
if ( !template.attributes ) {
Expand Down Expand Up @@ -1385,7 +1390,8 @@ function extendTemplate( template, def ) {
* @error ui-template-extend-children-mismatch
*/
throw new CKEditorError(
'ui-template-extend-children-mismatch: The number of children in extended definition does not match.'
'ui-template-extend-children-mismatch: The number of children in extended definition does not match.',
template
);
}

Expand Down
5 changes: 4 additions & 1 deletion src/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,10 @@ export default class View {
*
* @error ui-view-render-rendered
*/
throw new CKEditorError( 'ui-view-render-already-rendered: This View has already been rendered.' );
throw new CKEditorError(
'ui-view-render-already-rendered: This View has already been rendered.',
this
);
}

// Render #element of the view.
Expand Down
5 changes: 4 additions & 1 deletion src/viewcollection.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,10 @@ export default class ViewCollection extends Collection {
*
* @error ui-viewcollection-delegate-wrong-events
*/
throw new CKEditorError( 'ui-viewcollection-delegate-wrong-events: All event names must be strings.' );
throw new CKEditorError(
'ui-viewcollection-delegate-wrong-events: All event names must be strings.',
this
);
}

return {
Expand Down
15 changes: 8 additions & 7 deletions tests/componentfactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@

import Editor from '@ckeditor/ckeditor5-core/src/editor/editor';
import ComponentFactory from '../src/componentfactory';
import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';

import { expectToThrowCKEditorError } from '@ckeditor/ckeditor5-utils/tests/_utils/utils';

describe( 'ComponentFactory', () => {
let editor, factory;
Expand Down Expand Up @@ -41,17 +42,17 @@ describe( 'ComponentFactory', () => {
it( 'throws when trying to override already registered component', () => {
factory.add( 'foo', () => {} );

expect( () => {
expectToThrowCKEditorError( () => {
factory.add( 'foo', () => {} );
} ).to.throw( CKEditorError, /^componentfactory-item-exists/ );
}, /^componentfactory-item-exists/, editor );
} );

it( 'throws when trying to override already registered component added with different case', () => {
factory.add( 'Foo', () => {} );

expect( () => {
expectToThrowCKEditorError( () => {
factory.add( 'foo', () => {} );
} ).to.throw( CKEditorError, /^componentfactory-item-exists/ );
}, /^componentfactory-item-exists/, editor );
} );

it( 'does not normalize component names', () => {
Expand All @@ -63,9 +64,9 @@ describe( 'ComponentFactory', () => {

describe( 'create()', () => {
it( 'throws when trying to create a component which has not been registered', () => {
expect( () => {
expectToThrowCKEditorError( () => {
factory.create( 'foo' );
} ).to.throw( CKEditorError, /^componentfactory-item-missing/ );
}, /^componentfactory-item-missing/, editor );
} );

it( 'creates an instance', () => {
Expand Down
4 changes: 1 addition & 3 deletions tests/dropdown/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

/* globals document Event */

import utilsTestUtils from '@ckeditor/ckeditor5-utils/tests/_utils/utils';
import { assertBinding } from '@ckeditor/ckeditor5-utils/tests/_utils/utils';
import { keyCodes } from '@ckeditor/ckeditor5-utils/src/keyboard';
import Collection from '@ckeditor/ckeditor5-utils/src/collection';

Expand All @@ -23,8 +23,6 @@ import ListItemView from '../../src/list/listitemview';
import ListSeparatorView from '../../src/list/listseparatorview';
import ListView from '../../src/list/listview';

const assertBinding = utilsTestUtils.assertBinding;

describe( 'utils', () => {
let locale, dropdownView;

Expand Down
33 changes: 17 additions & 16 deletions tests/panel/balloon/contextualballoon.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ import ClassicTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/classictest
import ContextualBalloon from '../../../src/panel/balloon/contextualballoon';
import BalloonPanelView from '../../../src/panel/balloon/balloonpanelview';
import View from '../../../src/view';
import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';

import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
import { setData as setModelData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
import { add as addTranslations, _clear as clearTranslations } from '@ckeditor/ckeditor5-utils/src/translation-service';
import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
import { expectToThrowCKEditorError } from '@ckeditor/ckeditor5-utils/tests/_utils/utils';

/* global document, Event */

Expand Down Expand Up @@ -238,15 +239,15 @@ describe( 'ContextualBalloon', () => {
} );

it( 'should throw an error when try to add the same view more than once', () => {
expect( () => {
expectToThrowCKEditorError( () => {
balloon.add( {
view: viewA,
position: {
target: 'fake',
limiter: balloon.positionLimiter
}
} );
} ).to.throw( CKEditorError, /^contextualballoon-add-view-exist/ );
}, /^contextualballoon-add-view-exist/, editor );
} );

it( 'should use a provided limiter instead of #positionLimiter', () => {
Expand Down Expand Up @@ -459,9 +460,9 @@ describe( 'ContextualBalloon', () => {
} );

it( 'should throw an error when there is no stack of given id', () => {
expect( () => {
expectToThrowCKEditorError( () => {
balloon.showStack( 'second' );
} ).to.throw( CKEditorError, /^contextualballoon-showstack-stack-not-exist/ );
}, /^contextualballoon-showstack-stack-not-exist/, editor );
} );
} );

Expand Down Expand Up @@ -503,9 +504,9 @@ describe( 'ContextualBalloon', () => {
balloon.remove( viewB );

expect( balloon.visibleView ).to.equal( viewA );
expect( () => {
expectToThrowCKEditorError( () => {
balloon.showStack( 'second' );
} ).to.throw();
}, /^contextualballoon-showstack-stack-not-exist/, editor );
} );

it( 'should switch stack to the next one when removed view was the last one in the visible stack', () => {
Expand All @@ -517,9 +518,9 @@ describe( 'ContextualBalloon', () => {
balloon.remove( viewA );

expect( balloon.visibleView ).to.equal( viewB );
expect( () => {
expectToThrowCKEditorError( () => {
balloon.showStack( 'main' );
} ).to.throw();
}, /^contextualballoon-showstack-stack-not-exist/, editor );
} );

it( 'should remove given view and set preceding in the stack as visible when removed view was visible', () => {
Expand Down Expand Up @@ -592,15 +593,15 @@ describe( 'ContextualBalloon', () => {
expect( balloon.hasView( viewB ) ).to.false;

// Does throw, so the stack is not there.
expect( () => {
expectToThrowCKEditorError( () => {
balloon.showStack( 'second' );
} ).to.throw();
}, /^contextualballoon-showstack-stack-not-exist/, editor );
} );

it( 'should throw an error when there is no given view in the stack', () => {
expect( () => {
expectToThrowCKEditorError( () => {
balloon.remove( viewB );
} ).to.throw( CKEditorError, /^contextualballoon-remove-view-not-exist/ );
}, /^contextualballoon-remove-view-not-exist/, editor );
} );

it( 'should set additional css class of visible view to BalloonPanelView', () => {
Expand Down Expand Up @@ -707,9 +708,9 @@ describe( 'ContextualBalloon', () => {
} );

it( 'should throw an error when there is no given view in the stack', () => {
expect( () => {
expectToThrowCKEditorError( () => {
balloon.remove( viewB );
} ).to.throw( CKEditorError, /^contextualballoon-remove-view-not-exist/ );
}, /^contextualballoon-remove-view-not-exist/, editor );
} );
} );

Expand All @@ -718,7 +719,7 @@ describe( 'ContextualBalloon', () => {
expect( () => {
balloon.destroy();
balloon.destroy();
} ).to.not.throw();
} );
} );

it( 'should not touch the DOM', () => {
Expand Down
Loading

0 comments on commit 4fee7c3

Please sign in to comment.