Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use same format for error name in attachLinkToDocumentation as in CKEditorError #8124

Merged
merged 3 commits into from
Sep 24, 2020
Merged
Show file tree
Hide file tree
Changes from 2 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
12 changes: 5 additions & 7 deletions packages/ckeditor5-core/src/plugincollection.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,12 +206,12 @@ export default class PluginCollection {
* @error plugincollection-plugin-not-found
* @param {Array.<String>} plugins The name of the plugins which could not be loaded.
*/
const errorMsg = 'plugincollection-plugin-not-found: Some plugins are not available and could not be loaded.';
const errorId = 'plugincollection-plugin-not-found';
jodator marked this conversation as resolved.
Show resolved Hide resolved

// Log the error so it's more visible on the console. Hopefully, for better DX.
console.error( attachLinkToDocumentation( errorMsg ), { plugins: missingPlugins } );
// Log the error, so it's more visible on the console. Hopefully, for better DX.
console.error( attachLinkToDocumentation( errorId ), { plugins: missingPlugins } );

return Promise.reject( new CKEditorError( errorMsg, context, { plugins: missingPlugins } ) );
return Promise.reject( new CKEditorError( errorId, context, { plugins: missingPlugins } ) );
}

return Promise.all( pluginConstructors.map( loadPlugin ) )
Expand Down Expand Up @@ -251,9 +251,7 @@ export default class PluginCollection {
* @error plugincollection-load
* @param {String} plugin The name of the plugin that could not be loaded.
*/
console.error( attachLinkToDocumentation(
'plugincollection-load: It was not possible to load the plugin.'
), { plugin: PluginConstructor } );
console.error( attachLinkToDocumentation( 'plugincollection-load' ), { plugin: PluginConstructor } );

throw err;
} );
Expand Down
8 changes: 1 addition & 7 deletions packages/ckeditor5-engine/src/conversion/upcasthelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -349,13 +349,7 @@ export default class UpcastHelpers extends ConversionHelpers {
*
* @error upcast-helpers-element-to-marker-deprecated
*/
console.warn(
attachLinkToDocumentation(
'upcast-helpers-element-to-marker-deprecated: ' +
'The UpcastHelpers#elementToMarker() method was deprecated and will be removed in the near future. ' +
'Please use UpcastHelpers#dataToMarker() instead.'
)
);
console.warn( attachLinkToDocumentation( 'upcast-helpers-element-to-marker-deprecated' ) );

return this.add( upcastElementToMarker( config ) );
}
Expand Down
8 changes: 7 additions & 1 deletion packages/ckeditor5-image/src/imagestyle/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,14 @@ function _normalizeStyle( style ) {
}
// If it's just a name but none of the defaults, warn because probably it's a mistake.
else {
/**
* There is no such image style of given name.
*
* @error image-style-not-found
* @param {String} name Name of a missing style name.
*/
console.warn(
attachLinkToDocumentation( 'image-style-not-found: There is no such image style of given name.' ),
attachLinkToDocumentation( 'image-style-not-found' ),
{ name: styleName }
);

Expand Down
6 changes: 2 additions & 4 deletions packages/ckeditor5-media-embed/src/mediaregistry.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,9 @@ export default class MediaRegistry {
* has no name and will not be used by the editor. In order to get this media
* provider working, double check your editor configuration.
*
* @warning media-embed-no-provider-name
* @error media-embed-no-provider-name
*/
console.warn( attachLinkToDocumentation(
'media-embed-no-provider-name: The configured media provider has no name and cannot be used.'
), { provider } );
console.warn( attachLinkToDocumentation( 'media-embed-no-provider-name' ), { provider } );

return false;
}
Expand Down
4 changes: 2 additions & 2 deletions packages/ckeditor5-media-embed/tests/mediaembedediting.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ describe( 'MediaEmbedEditing', () => {
providers: [ provider ]
} ).then( () => {
expect( consoleWarnStub.calledOnce ).to.equal( true );
expect( consoleWarnStub.firstCall.args[ 0 ] ).to.match( /^media-embed-no-provider-name:/ );
expect( consoleWarnStub.firstCall.args[ 0 ] ).to.match( /^media-embed-no-provider-name/ );
expect( consoleWarnStub.firstCall.args[ 1 ].provider ).to.deep.equal( provider );
} );
} );
Expand Down Expand Up @@ -333,7 +333,7 @@ describe( 'MediaEmbedEditing', () => {
extraProviders: [ provider ]
} ).then( () => {
expect( consoleWarnStub.calledOnce ).to.equal( true );
expect( consoleWarnStub.firstCall.args[ 0 ] ).to.match( /^media-embed-no-provider-name:/ );
expect( consoleWarnStub.firstCall.args[ 0 ] ).to.match( /^media-embed-no-provider-name/ );
expect( consoleWarnStub.firstCall.args[ 1 ].provider ).to.deep.equal( provider );
} );
} );
Expand Down
2 changes: 1 addition & 1 deletion packages/ckeditor5-media-embed/tests/mediaembedtoolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ describe( 'MediaEmbedToolbar - integration with BalloonEditor', () => {

expect( widgetToolbarRepository._toolbarDefinitions.get( 'mediaEmbed' ) ).to.be.undefined;
expect( consoleWarnStub.calledOnce ).to.equal( true );
expect( consoleWarnStub.firstCall.args[ 0 ] ).to.match( /^widget-toolbar-no-items:/ );
expect( consoleWarnStub.firstCall.args[ 0 ] ).to.match( /^widget-toolbar-no-items/ );

element.remove();
return editor.destroy();
Expand Down
2 changes: 1 addition & 1 deletion packages/ckeditor5-mention/src/mentionui.js
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ export default class MentionUI extends Plugin {
*
* @error mention-feed-callback-error
*/
console.warn( attachLinkToDocumentation( 'mention-feed-callback-error: Could not obtain mention autocomplete feed.' ) );
console.warn( attachLinkToDocumentation( 'mention-feed-callback-error' ) );
} );
}

Expand Down
2 changes: 1 addition & 1 deletion packages/ckeditor5-mention/tests/mentionui.js
Original file line number Diff line number Diff line change
Expand Up @@ -1249,7 +1249,7 @@ describe( 'MentionUI', () => {
expect( panelView.isVisible, 'panel is hidden' ).to.be.false;
expect( editor.model.markers.has( 'mention' ), 'there is no marker' ).to.be.false;

sinon.assert.calledWithExactly( warnSpy, sinon.match( /^mention-feed-callback-error:/ ) );
sinon.assert.calledWithExactly( warnSpy, sinon.match( /^mention-feed-callback-error/ ) );
sinon.assert.calledOnce( eventSpy );
} );
} );
Expand Down
2 changes: 1 addition & 1 deletion packages/ckeditor5-table/src/tablewalker.js
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ class TableSlot {
*/

// @if CK_DEBUG // function throwMissingGetterError( getterName ) {
// @if CK_DEBUG // throw new CKEditorError( 'tableslot-getter-removed: This TableSlot getter does not exist anymore.', this, {
// @if CK_DEBUG // throw new CKEditorError( 'tableslot-getter-removed', this, {
// @if CK_DEBUG // getterName
// @if CK_DEBUG // } );
// @if CK_DEBUG // }
3 changes: 1 addition & 2 deletions packages/ckeditor5-ui/src/toolbar/toolbarview.js
Original file line number Diff line number Diff line change
Expand Up @@ -299,8 +299,7 @@ export default class ToolbarView extends View {
* @error toolbarview-item-unavailable
* @param {String} name The name of the component.
*/
console.warn( attachLinkToDocumentation(
'toolbarview-item-unavailable: The requested toolbar item is unavailable.' ), { name } );
console.warn( attachLinkToDocumentation( 'toolbarview-item-unavailable' ), { name } );
}
} ).filter( item => item !== undefined ) );
}
Expand Down
6 changes: 2 additions & 4 deletions packages/ckeditor5-upload/src/adapters/simpleuploadadapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,9 @@ export default class SimpleUploadAdapter extends Plugin {
* configuration required by the {@link module:upload/adapters/simpleuploadadapter~SimpleUploadAdapter `SimpleUploadAdapter`}
* is missing. Make sure the correct URL is specified for the image upload to work properly.
*
* @error simple-upload-adapter-missing-uploadUrl
* @error simple-upload-adapter-missing-uploadurl
*/
console.warn( attachLinkToDocumentation(
'simple-upload-adapter-missing-uploadUrl: Missing the "uploadUrl" property in the "simpleUpload" editor configuration.'
) );
console.warn( attachLinkToDocumentation( 'simple-upload-adapter-missing-uploadurl' ) );

return;
}
Expand Down
4 changes: 1 addition & 3 deletions packages/ckeditor5-upload/src/filerepository.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,7 @@ export default class FileRepository extends Plugin {
*
* @error filerepository-no-upload-adapter
*/
console.warn( attachLinkToDocumentation(
'filerepository-no-upload-adapter: Upload adapter is not defined.'
) );
console.warn( attachLinkToDocumentation( 'filerepository-no-upload-adapter' ) );

return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ describe( 'SimpleUploadAdapter', () => {
} )
.then( editor => {
expect( consoleWarnStub.callCount ).to.equal( 1 );
expect( consoleWarnStub.firstCall.args[ 0 ] ).to.match( /^simple-upload-adapter-missing-uploadUrl/ );
expect( consoleWarnStub.firstCall.args[ 0 ] ).to.match( /^simple-upload-adapter-missing-uploadurl/ );

const fileRepository = editor.plugins.get( FileRepository );

Expand Down
2 changes: 1 addition & 1 deletion packages/ckeditor5-upload/tests/filerepository.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ describe( 'FileRepository', () => {
sinon.assert.calledOnce( consoleWarnStub );
sinon.assert.calledWithExactly(
consoleWarnStub,
sinon.match( 'filerepository-no-upload-adapter: Upload adapter is not defined.' )
sinon.match( /^filerepository-no-upload-adapter/ )
);
} );

Expand Down
27 changes: 9 additions & 18 deletions packages/ckeditor5-utils/src/ckeditorerror.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const DOCUMENTATION_URL =
* * @param pluginName The name of the plugin that could not be loaded.
* * @param moduleName The name of the module which tried to load this plugin.
* * /
* throw new CKEditorError( 'plugin-load: It was not possible to load the "{$pluginName}" plugin in module "{$moduleName}', {
* throw new CKEditorError( 'plugin-load', {
* pluginName: 'foo',
* moduleName: 'bar'
* } );
Expand All @@ -44,9 +44,8 @@ export default class CKEditorError extends Error {
/**
* Creates an instance of the CKEditorError class.
*
* @param {String} message The error message in an `error-name: Error message.` format.
* During the minification process the "Error message" part will be removed to limit the code size
* and a link to this error documentation will be added to the `message`.
* @param {String} errorName The error id in an `error-name` format. A link to this error documentation page will be added
* to the thrown error's `message`.
* @param {Object|null} context A context of the error by which the {@link module:watchdog/watchdog~Watchdog watchdog}
* is able to determine which editor crashed. It should be an editor instance or a property connected to it. It can be also
* a `null` value if the editor should not be restarted in case of the error (e.g. during the editor initialization).
Expand All @@ -56,8 +55,8 @@ export default class CKEditorError extends Error {
* will be appended to the error message, so the data are quickly visible in the console. The original
* data object will also be later available under the {@link #data} property.
*/
constructor( message, context, data ) {
message = attachLinkToDocumentation( message );
constructor( errorName, context, data ) {
let message = attachLinkToDocumentation( errorName );

if ( data ) {
message += ' ' + JSON.stringify( data );
Expand Down Expand Up @@ -136,19 +135,11 @@ export default class CKEditorError extends Error {
* * @error toolbarview-item-unavailable
* * @param {String} name The name of the component.
* * /
* console.warn( attachLinkToDocumentation(
* 'toolbarview-item-unavailable: The requested toolbar item is unavailable.' ), { name } );
* console.warn( attachLinkToDocumentation( 'toolbarview-item-unavailable' ), { name } );
*
* @param {String} message Message to be logged.
* @param {String} errorName Error name to be linked.
* @returns {String}
*/
export function attachLinkToDocumentation( message ) {
// The link to documentation should work with console.warn format: "message-id: Explanation message." and single error id.
const matchedErrorName = message.match( /^([a-z0-9]+-[a-z-0-9]+):?/ );

if ( !matchedErrorName ) {
return message;
}

return message + ` Read more: ${ DOCUMENTATION_URL }#error-${ matchedErrorName[ 1 ] }\n`;
export function attachLinkToDocumentation( errorName ) {
return errorName + ` Read more: ${ DOCUMENTATION_URL }#error-${ errorName }\n`;
}
10 changes: 8 additions & 2 deletions packages/ckeditor5-utils/tests/ckeditorerror.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ describe( 'CKEditorError', () => {
const data = { bar: 1 };
const error = new CKEditorError( 'foo', null, data );

expect( error ).to.have.property( 'message', 'foo {"bar":1}' );
expect( error ).to.have.property(
'message',
`foo Read more: ${ DOCUMENTATION_URL }#error-foo\n {"bar":1}`
);
expect( error ).to.have.property( 'data', data );
} );

Expand All @@ -59,7 +62,10 @@ describe( 'CKEditorError', () => {
};
const error = new CKEditorError( 'foo', null, data );

expect( error ).to.have.property( 'message', 'foo {"bar":"a","bom":{"x":1},"bim":10}' );
expect( error ).to.have.property(
'message',
`foo Read more: ${ DOCUMENTATION_URL }#error-foo\n {"bar":"a","bom":{"x":1},"bim":10}`
);
expect( error ).to.have.property( 'data', data );
} );

Expand Down
2 changes: 1 addition & 1 deletion packages/ckeditor5-watchdog/tests/editorwatchdog.js
Original file line number Diff line number Diff line change
Expand Up @@ -817,7 +817,7 @@ describe( 'EditorWatchdog', () => {
expect( watchdog.crashes[ 0 ].lineno ).to.be.a( 'number' );
expect( watchdog.crashes[ 0 ].colno ).to.be.a( 'number' );

expect( watchdog.crashes[ 1 ].message ).to.equal( 'bar' );
expect( watchdog.crashes[ 1 ].message ).to.match( /^bar/ );

watchdog.destroy().then( res );
} );
Expand Down
2 changes: 1 addition & 1 deletion packages/ckeditor5-widget/src/widgettoolbarrepository.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ export default class WidgetToolbarRepository extends Plugin {
* @error widget-toolbar-no-items
*/
console.warn(
attachLinkToDocumentation( 'widget-toolbar-no-items: Trying to register a toolbar without items.' ), { toolbarId }
attachLinkToDocumentation( 'widget-toolbar-no-items' ), { toolbarId }
);

return;
Expand Down
2 changes: 1 addition & 1 deletion packages/ckeditor5-widget/tests/widgettoolbarrepository.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ describe( 'WidgetToolbarRepository', () => {
expect( widgetToolbarRepository._toolbarDefinitions.get( 'fake' ) ).to.be.undefined;

expect( consoleWarnStub.calledOnce ).to.equal( true );
expect( consoleWarnStub.firstCall.args[ 0 ] ).to.match( /^widget-toolbar-no-items:/ );
expect( consoleWarnStub.firstCall.args[ 0 ] ).to.match( /^widget-toolbar-no-items/ );
} );
} );

Expand Down