Skip to content

Commit

Permalink
Update errors messages formatting (#26016)
Browse files Browse the repository at this point in the history
  • Loading branch information
IlyaKhD authored Nov 20, 2023
1 parent 66fe85c commit d201203
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 13 deletions.
2 changes: 1 addition & 1 deletion packages/devextreme/js/core/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ export default errorUtils({
/**
* @name ErrorsCore.W0019
*/
W0019: 'DevExtreme: Unable to Locate a Valid License Key\n\n' +
W0019: 'DevExtreme: Unable to Locate a Valid License Key.\n\n' +
'If you are using a 30-day trial version of DevExtreme, you must uninstall all copies of DevExtreme once your 30-day trial period expires. For terms and conditions that govern use of DevExtreme UI components/libraries, please refer to the DevExtreme End User License Agreement: https://js.devexpress.com/EULAs/DevExtremeComplete.\n\n' +
'To use DevExtreme in a commercial project, you must purchase a license. For pricing/licensing options, please visit: https://js.devexpress.com/Buy.\n\n' +
'If you have licensing-related questions or need help with a purchase, please email [email protected].\n\n',
Expand Down
3 changes: 2 additions & 1 deletion packages/devextreme/js/core/utils/error.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ export default function(baseErrors, errors) {
}

function formatMessage(id, details) {
return format.apply(this, ['{0} - {1}. See:\n{2}', id, details, getErrorUrl(id)]);
const kind = id?.startsWith('W') ? 'warning' : 'error';
return format.apply(this, ['{0} - {1}.\n\nFor additional information on this {2} message, see: {3}', id, details, kind, getErrorUrl(id)]);
}

function makeError(args) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ const mockVersion = function(s) {

QUnit.test('\'log\' method logs error on console if ID is matched to error id pattern', function(assert) {
errors.log('E1');
assert.deepEqual(mockVersion(this.log[0].error), 'E1 - Error 1. See:\nhttp://js.devexpress.com/error/[VERSION]/E1');
assert.deepEqual(mockVersion(this.log[0].error), 'E1 - Error 1.\n\nFor additional information on this error message, see: http://js.devexpress.com/error/[VERSION]/E1');
});

QUnit.test('\'log\' method logs warning on console if ID is matched to warning id pattern', function(assert) {
errors.log('W1');
assert.deepEqual(mockVersion(this.log[0].warn), 'W1 - Warning 1. See:\nhttp://js.devexpress.com/error/[VERSION]/W1');
assert.deepEqual(mockVersion(this.log[0].warn), 'W1 - Warning 1.\n\nFor additional information on this warning message, see: http://js.devexpress.com/error/[VERSION]/W1');
});

QUnit.test('\'log\' method logs message on console if ID is not matched to any patterns', function(assert) {
Expand All @@ -57,7 +57,7 @@ QUnit.test('\'log\' method logs message on console if ID is not matched to any p
QUnit.test('\'Error\' method creates Error instance', function(assert) {
const error = errors.Error('E1');
assert.ok(error instanceof Error);
assert.equal(mockVersion(error.message), 'E1 - Error 1. See:\nhttp://js.devexpress.com/error/[VERSION]/E1');
assert.equal(mockVersion(error.message), 'E1 - Error 1.\n\nFor additional information on this error message, see: http://js.devexpress.com/error/[VERSION]/E1');
});

QUnit.test('\'Error\' method called with \'new\' returns Error instance', function(assert) {
Expand All @@ -73,13 +73,13 @@ QUnit.test('\'Error\' method creates Error with \'__details\' and \'__id\' prope

QUnit.test('\'Error\' method create Error with no unnecessary dots', function(assert) {
const error = errors.Error('E2');
assert.equal(mockVersion(error.message), 'E2 - Error 2. See:\nhttp://js.devexpress.com/error/[VERSION]/E2');
assert.equal(mockVersion(error.message), 'E2 - Error 2.\n\nFor additional information on this error message, see: http://js.devexpress.com/error/[VERSION]/E2');
});

QUnit.test('\'log\' and \'error\' method support string formatting', function(assert) {
errors.log('W2', 'Core');
assert.deepEqual(mockVersion(this.log[0].warn), 'W2 - Core module is not initialized. See:\nhttp://js.devexpress.com/error/[VERSION]/W2');
assert.deepEqual(mockVersion(this.log[0].warn), 'W2 - Core module is not initialized.\n\nFor additional information on this warning message, see: http://js.devexpress.com/error/[VERSION]/W2');

const error = errors.Error('W2', 'Core');
assert.equal(mockVersion(error.message), 'W2 - Core module is not initialized. See:\nhttp://js.devexpress.com/error/[VERSION]/W2');
assert.equal(mockVersion(error.message), 'W2 - Core module is not initialized.\n\nFor additional information on this warning message, see: http://js.devexpress.com/error/[VERSION]/W2');
});
Original file line number Diff line number Diff line change
Expand Up @@ -836,7 +836,7 @@ QUnit.test('Should show E4024 error when searching or filtering an Int32 field (

function assertFunc(message, operation) {
assert.equal(message.replace(/\d+_\d+/, '[VERSION]'),
`E4024 - String function ${operation} cannot be used with the data field id of type Int32. See:\nhttp://js.devexpress.com/error/[VERSION]/E4024`);
`E4024 - String function ${operation} cannot be used with the data field id of type Int32.\n\nFor additional information on this error message, see: http://js.devexpress.com/error/[VERSION]/E4024`);
}

const promises = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2668,7 +2668,7 @@ QUnit.module('Supported editors', () => {
const errorMessage = consoleErrorStub.getCall(0).args[0];
assert.equal(consoleErrorStub.callCount, 1, 'error was raised for item without dataField and editorType');
assert.equal(errorMessage.indexOf('E1035 - The editor cannot be created'), 0);
assert.ok(errorMessage.indexOf('See:\nhttp://js.devexpress.com/error/') > 0);
assert.ok(errorMessage.indexOf('\n\nFor additional information on this error message, see: http://js.devexpress.com/error/') > 0);
consoleErrorStub.restore();
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1137,7 +1137,7 @@ QUnit.test('in default output message with url in logger. without arguments', fu
this.triggerIncident('E100');

assert.ok(this.error.calledOnce);
assert.equal(this.error.firstCall.args[0].replace(/\d+_\d+/, '0_1'), 'E100 - Templated text 1: {0}, Templated text 2: {1}. See:\nhttp://js.devexpress.com/error/0_1/E100');
assert.equal(this.error.firstCall.args[0].replace(/\d+_\d+/, '0_1'), 'E100 - Templated text 1: {0}, Templated text 2: {1}.\n\nFor additional information on this error message, see: http://js.devexpress.com/error/0_1/E100');
});

QUnit.test('default incidentOccurred show warning', function(assert) {
Expand All @@ -1146,7 +1146,7 @@ QUnit.test('default incidentOccurred show warning', function(assert) {
this.triggerIncident('W100');

assert.ok(this.warn.calledOnce);
assert.equal(this.warn.firstCall.args[0].replace(/\d+_\d+/, '0_1'), 'W100 - Warning: Templated text 1: {0}, Templated text 2: {1}. See:\nhttp://js.devexpress.com/error/0_1/W100');
assert.equal(this.warn.firstCall.args[0].replace(/\d+_\d+/, '0_1'), 'W100 - Warning: Templated text 1: {0}, Templated text 2: {1}.\n\nFor additional information on this warning message, see: http://js.devexpress.com/error/0_1/W100');
});

QUnit.test('in default output message with url in logger', function(assert) {
Expand All @@ -1155,7 +1155,7 @@ QUnit.test('in default output message with url in logger', function(assert) {
this.triggerIncident('E100', ['argument1', 'argument2']);

assert.ok(this.error.calledOnce);
assert.equal(this.error.firstCall.args[0].replace(/\d+_\d+/, '0_1'), 'E100 - Templated text 1: argument1, Templated text 2: argument2. See:\nhttp://js.devexpress.com/error/0_1/E100');
assert.equal(this.error.firstCall.args[0].replace(/\d+_\d+/, '0_1'), 'E100 - Templated text 1: argument1, Templated text 2: argument2.\n\nFor additional information on this error message, see: http://js.devexpress.com/error/0_1/E100');
});

QUnit.module('drawn', $.extend({}, environment, {
Expand Down

0 comments on commit d201203

Please sign in to comment.