Chore: cleans up Canvas function error messages (#28194) (#28406)

* Added op value to compare error message. Removed duplicate unit test

* Added single quotes to ply error message to help distinguish incorrect value

* Added value of context to progress error message

* Added percent value to reveal image error message

* Added single quotes to alterColumn error message to help distinguish incorrect value

* Added single quotes to timefilter error message to help distinguish incorrect value

* Added single quotes to axisConfg error message to help distinguish incorrect value

* Cleaned up error message in compare

* Added single quotes to font error messages

* Added single quotes to getCell error messages

* Added single quotes to progress error messages

* Added single quotes to revealImage error messages

* Cleaned up timefilter error message

* Added single quotes to demodata error messages

* Added unit test back

* Updated error message in ply
This commit is contained in:
Catherine Liu 2019-01-09 12:55:22 -07:00 committed by GitHub
parent d7c2a9823d
commit 3fc24850e4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
20 changed files with 43 additions and 37 deletions

View file

@ -79,7 +79,7 @@ describe('alterColumn', () => {
it('throws when converting to an invalid type', () => {
expect(() => fn(testTable, { column: 'name', type: 'foo' })).to.throwException(e => {
expect(e.message).to.be('Cannot convert to foo');
expect(e.message).to.be(`Cannot convert to 'foo'`);
});
});
});

View file

@ -59,7 +59,7 @@ describe('axisConfig', () => {
expect(fn)
.withArgs(testTable, { position: 'foo' })
.to.throwException(e => {
expect(e.message).to.be('Invalid position foo');
expect(e.message).to.be(`Invalid position: 'foo'`);
});
});
});
@ -83,7 +83,7 @@ describe('axisConfig', () => {
.withArgs(testTable, { min: 'foo' })
.to.throwException(e => {
expect(e.message).to.be(
`Invalid date string 'foo' found. 'min' must be a number, date in ms, or ISO8601 date string`
`Invalid date string: 'foo'. 'min' must be a number, date in ms, or ISO8601 date string`
);
});
});
@ -108,7 +108,7 @@ describe('axisConfig', () => {
.withArgs(testTable, { max: '20/02/17' })
.to.throwException(e => {
expect(e.message).to.be(
`Invalid date string '20/02/17' found. 'max' must be a number, date in ms, or ISO8601 date string`
`Invalid date string: '20/02/17'. 'max' must be a number, date in ms, or ISO8601 date string`
);
});
});

View file

@ -24,10 +24,14 @@ describe('compare', () => {
it('throws when invalid op is provided', () => {
expect(() => fn(1, { op: 'boo', to: 2 })).to.throwException(e => {
expect(e.message).to.be('Invalid compare operator. Use eq, ne, lt, gt, lte, or gte.');
expect(e.message).to.be(
`Invalid compare operator: 'boo'. Use eq, ne, lt, gt, lte, or gte.`
);
});
expect(() => fn(1, { op: 'boo' })).to.throwException(e => {
expect(e.message).to.be('Invalid compare operator. Use eq, ne, lt, gt, lte, or gte.');
expect(e.message).to.be(
`Invalid compare operator: 'boo'. Use eq, ne, lt, gt, lte, or gte.`
);
});
});
});

View file

@ -105,7 +105,7 @@ describe('font', () => {
it('throws when provided an invalid weight', () => {
expect(() => fn(null, { weight: 'foo' })).to.throwException(e => {
expect(e.message).to.be('Invalid font weight: foo');
expect(e.message).to.be(`Invalid font weight: 'foo'`);
});
});
});
@ -175,7 +175,7 @@ describe('font', () => {
expect(fn)
.withArgs(null, { align: 'foo' })
.to.throwException(e => {
expect(e.message).to.be('Invalid text alignment: foo');
expect(e.message).to.be(`Invalid text alignment: 'foo'`);
});
});
});

View file

@ -44,7 +44,7 @@ describe('getCell', () => {
it('throws when invalid column is provided', () => {
expect(() => fn(testTable, { column: 'foo' })).to.throwException(e => {
expect(e.message).to.be('Column not found: foo');
expect(e.message).to.be(`Column not found: 'foo'`);
});
});
});
@ -66,15 +66,15 @@ describe('getCell', () => {
const invalidRow = testTable.rows.length;
expect(() => fn(testTable, { column: 'name', row: invalidRow })).to.throwException(e => {
expect(e.message).to.be(`Row not found: ${invalidRow}`);
expect(e.message).to.be(`Row not found: '${invalidRow}'`);
});
expect(() => fn(emptyTable, { column: 'foo' })).to.throwException(e => {
expect(e.message).to.be('Row not found: 0');
expect(e.message).to.be(`Row not found: '0'`);
});
expect(() => fn(emptyTable)).to.throwException(e => {
expect(e.message).to.be('Row not found: 0');
expect(e.message).to.be(`Row not found: '0'`);
});
});
});

View file

@ -82,12 +82,12 @@ describe('ply', () => {
it('throws when by is an invalid column', () => {
expect(() => fn(testTable, { by: [''], expression: [averagePrice] })).to.throwException(
e => {
expect(e.message).to.be('No such column: ');
expect(e.message).to.be(`Column not found: ''`);
}
);
expect(() => fn(testTable, { by: ['foo'], expression: [averagePrice] })).to.throwException(
e => {
expect(e.message).to.be('No such column: foo');
expect(e.message).to.be(`Column not found: 'foo'`);
}
);
});

View file

@ -29,7 +29,7 @@ describe('progress', () => {
expect(fn)
.withArgs(3)
.to.throwException(e => {
expect(e.message).to.be('Context must be between 0 and 1');
expect(e.message).to.be(`Invalid value: '3'. Value must be between 0 and 1`);
});
});
@ -65,7 +65,7 @@ describe('progress', () => {
expect(fn)
.withArgs(value, { max: -0.5 })
.to.throwException(e => {
expect(e.message).to.be(`'max' must be greater than 0`);
expect(e.message).to.be(`Invalid max value: '-0.5'. 'max' must be greater than 0`);
});
});
});

View file

@ -29,7 +29,7 @@ describe('revealImage', () => {
origin: 'top',
})
.to.throwException(e => {
expect(e.message).to.be.equal('input must be between 0 and 1');
expect(e.message).to.be.equal(`Invalid value: '10'. Percentage must be between 0 and 1`);
});
expect(fn)
@ -39,7 +39,9 @@ describe('revealImage', () => {
origin: 'top',
})
.to.throwException(e => {
expect(e.message).to.be.equal('input must be between 0 and 1');
expect(e.message).to.be.equal(
`Invalid value: '-0.1'. Percentage must be between 0 and 1`
);
});
});
});

View file

@ -88,7 +88,7 @@ describe('timefilter', () => {
it('throws when provided an invalid date string', () => {
expect(() => fn(emptyFilter, { from: '2018-13-42T15:00:00.950Z' })).to.throwException(e => {
expect(e.message).to.be.equal('Invalid date/time string 2018-13-42T15:00:00.950Z');
expect(e.message).to.be.equal(`Invalid date/time string: '2018-13-42T15:00:00.950Z'`);
});
});
});

View file

@ -74,7 +74,7 @@ export const alterColumn = () => ({
case 'null':
return () => null;
default:
throw new Error(`Cannot convert to ${type}`);
throw new Error(`Cannot convert to '${type}'`);
}
})();
}

View file

@ -43,7 +43,7 @@ export const axisConfig = () => ({
fn: (context, args) => {
const positions = ['top', 'bottom', 'left', 'right', ''];
if (!positions.includes(args.position)) {
throw new Error(`Invalid position ${args.position}`);
throw new Error(`Invalid position: '${args.position}'`);
}
const min = typeof args.min === 'string' ? moment.utc(args.min).valueOf() : args.min;
@ -51,16 +51,16 @@ export const axisConfig = () => ({
if (min != null && isNaN(min)) {
throw new Error(
`Invalid date string '${
`Invalid date string: '${
args.min
}' found. 'min' must be a number, date in ms, or ISO8601 date string`
}'. 'min' must be a number, date in ms, or ISO8601 date string`
);
}
if (max != null && isNaN(max)) {
throw new Error(
`Invalid date string '${
`Invalid date string: '${
args.max
}' found. 'max' must be a number, date in ms, or ISO8601 date string`
}'. 'max' must be a number, date in ms, or ISO8601 date string`
);
}

View file

@ -61,7 +61,7 @@ export const compare = () => ({
}
return false;
default:
throw new Error('Invalid compare operator. Use eq, ne, lt, gt, lte, or gte.');
throw new Error(`Invalid compare operator: '${op}'. Use eq, ne, lt, gt, lte, or gte.`);
}
return false;

View file

@ -80,10 +80,10 @@ export const font = () => ({
},
fn: (context, args) => {
if (!weights.includes(args.weight)) {
throw new Error(`Invalid font weight: ${args.weight}`);
throw new Error(`Invalid font weight: '${args.weight}'`);
}
if (!alignments.includes(args.align)) {
throw new Error(`Invalid text alignment: ${args.align}`);
throw new Error(`Invalid text alignment: '${args.align}'`);
}
// the line height shouldn't ever be lower than the size

View file

@ -26,14 +26,14 @@ export const getCell = () => ({
fn: (context, args) => {
const row = context.rows[args.row];
if (!row) {
throw new Error(`Row not found: ${args.row}`);
throw new Error(`Row not found: '${args.row}'`);
}
const { column = context.columns[0].name } = args;
const value = row[column];
if (typeof value === 'undefined') {
throw new Error(`Column not found: ${column}`);
throw new Error(`Column not found: '${column}'`);
}
return value;

View file

@ -95,7 +95,7 @@ export const ply = () => ({
byColumns = args.by.map(by => {
const column = context.columns.find(column => column.name === by);
if (!column) {
throw new Error(`No such column: ${by}`);
throw new Error(`Column not found: '${by}'`);
}
return column;
});

View file

@ -72,10 +72,10 @@ export const progress = () => ({
},
fn: (value, args) => {
if (args.max <= 0) {
throw new Error(`'max' must be greater than 0`);
throw new Error(`Invalid max value: '${args.max}'. 'max' must be greater than 0`);
}
if (value > args.max || value < 0) {
throw new Error(`Context must be between 0 and ${args.max}`);
throw new Error(`Invalid value: '${value}'. Value must be between 0 and ${args.max}`);
}
let label = '';

View file

@ -35,7 +35,7 @@ export const revealImage = () => ({
},
fn: (percent, args) => {
if (percent > 1 || percent < 0) {
throw new Error('input must be between 0 and 1');
throw new Error(`Invalid value: '${percent}'. Percentage must be between 0 and 1`);
}
return {

View file

@ -50,7 +50,7 @@ export const timefilter = () => ({
const moment = dateMath.parse(str);
if (!moment || !moment.isValid()) {
throw new Error(`Invalid date/time string ${str}`);
throw new Error(`Invalid date/time string: '${str}'`);
}
return moment.toISOString();
}

View file

@ -36,7 +36,7 @@ describe('demodata', () => {
expect(fn)
.withArgs(null, { type: 'foo' })
.to.throwException(e => {
expect(e.message).to.be("Invalid data set: foo, use 'ci' or 'shirts'.");
expect(e.message).to.be("Invalid data set: 'foo', use 'ci' or 'shirts'.");
});
});
});

View file

@ -15,5 +15,5 @@ export function getDemoRows(arg) {
if (arg === 'shirts') {
return cloneDeep(shirts);
}
throw new Error(`Invalid data set: ${arg}, use 'ci' or 'shirts'.`);
throw new Error(`Invalid data set: '${arg}', use 'ci' or 'shirts'.`);
}