Skip to content

Commit 0ab3e2e

Browse files
committed
Format error messages
1 parent edad4e0 commit 0ab3e2e

File tree

36 files changed

+173
-159
lines changed

36 files changed

+173
-159
lines changed

lib/node_modules/@stdlib/_tools/docs/www/readme-database/lib/validate.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ var isObject = require( '@stdlib/assert/is-plain-object' );
2424
var hasOwnProp = require( '@stdlib/assert/has-own-property' );
2525
var isString = require( '@stdlib/assert/is-string' ).isPrimitive;
2626
var isStringArray = require( '@stdlib/assert/is-string-array' ).primitives;
27+
var format = require( '@stdlib/string/format' );
2728

2829

2930
// VARIABLES //
@@ -58,34 +59,33 @@ var RE = /package\.json$/;
5859
*/
5960
function validate( opts, options ) {
6061
if ( !isObject( options ) ) {
61-
return new TypeError( 'invalid argument. Options argument must be an object. Value: `' + options +
62-
'`.' );
62+
return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );
6363
}
6464
if ( hasOwnProp( options, 'dir' ) ) {
6565
opts.dir = options.dir;
6666
if ( !isString( opts.dir ) ) {
67-
return new TypeError( 'invalid option. `dir` option must be a primitive string. Option: `' + opts.dir + '`.' );
67+
return new TypeError( format( 'invalid option. `%s` option must be a string primitive. Option: `%s`.', 'dir', opts.dir ) );
6868
}
6969
}
7070
if ( hasOwnProp( options, 'pattern' ) ) {
7171
opts.pattern = options.pattern;
7272
if ( !isString( opts.pattern ) ) {
73-
return new TypeError( 'invalid option. `pattern` option must be a primitive string. Option: `' + opts.pattern + '`.' );
73+
return new TypeError( format( 'invalid option. `%s` option must be a string primitive. Option: `%s`.', 'pattern', opts.pattern ) );
7474
}
7575
if ( !RE.test( opts.pattern ) ) {
76-
return new Error( 'invalid option. `pattern` option must end with `package.json`. Option: `' + opts.pattern +'`.' );
76+
return new Error( format( 'invalid option. `%s` option must end with `package.json`. Option: `%s`.', 'pattern', opts.pattern ) );
7777
}
7878
}
7979
if ( hasOwnProp( options, 'ignore' ) ) {
8080
opts.ignore = options.ignore;
8181
if ( !isStringArray( opts.ignore ) ) {
82-
return new TypeError( 'invalid option. `ignore` option must be a string array. Option: `' + opts.ignore + '`.' );
82+
return new TypeError( format( 'invalid option. `%s` option must be a string array. Option: `%s`.', 'ignore', opts.ignore ) );
8383
}
8484
}
8585
if ( hasOwnProp( options, 'base' ) ) {
8686
opts.base = options.base;
8787
if ( !isString( opts.base ) ) {
88-
return new TypeError( 'invalid option. `base` option must be a primitive string. Option: `' + opts.base + '`.' );
88+
return new TypeError( format( 'invalid option. `%s` option must be a string primitive. Option: `%s`.', 'base', opts.base ) );
8989
}
9090
}
9191
return null;

lib/node_modules/@stdlib/_tools/docs/www/readme-fragment-file-tree/lib/validate.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ var isObject = require( '@stdlib/assert/is-plain-object' );
2424
var hasOwnProp = require( '@stdlib/assert/has-own-property' );
2525
var isString = require( '@stdlib/assert/is-string' ).isPrimitive;
2626
var isStringArray = require( '@stdlib/assert/is-string-array' ).primitives;
27+
var format = require( '@stdlib/string/format' );
2728

2829

2930
// VARIABLES //
@@ -58,34 +59,33 @@ var RE = /package\.json$/;
5859
*/
5960
function validate( opts, options ) {
6061
if ( !isObject( options ) ) {
61-
return new TypeError( 'invalid argument. Options argument must be an object. Value: `' + options +
62-
'`.' );
62+
return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );
6363
}
6464
if ( hasOwnProp( options, 'dir' ) ) {
6565
opts.dir = options.dir;
6666
if ( !isString( opts.dir ) ) {
67-
return new TypeError( 'invalid option. `dir` option must be a primitive string. Option: `' + opts.dir + '`.' );
67+
return new TypeError( format( 'invalid option. `%s` option must be a string primitive. Option: `%s`.', 'dir', opts.dir ) );
6868
}
6969
}
7070
if ( hasOwnProp( options, 'pattern' ) ) {
7171
opts.pattern = options.pattern;
7272
if ( !isString( opts.pattern ) ) {
73-
return new TypeError( 'invalid option. `pattern` option must be a primitive string. Option: `' + opts.pattern + '`.' );
73+
return new TypeError( format( 'invalid option. `%s` option must be a string primitive. Option: `%s`.', 'pattern', opts.pattern ) );
7474
}
7575
if ( !RE.test( opts.pattern ) ) {
76-
return new Error( 'invalid option. `pattern` option must end with `package.json`. Option: `' + opts.pattern +'`.' );
76+
return new Error( format( 'invalid option. `%s` option must end with `package.json`. Option: `%s`.', 'pattern', opts.pattern ) );
7777
}
7878
}
7979
if ( hasOwnProp( options, 'ignore' ) ) {
8080
opts.ignore = options.ignore;
8181
if ( !isStringArray( opts.ignore ) ) {
82-
return new TypeError( 'invalid option. `ignore` option must be a string array. Option: `' + opts.ignore + '`.' );
82+
return new TypeError( format( 'invalid option. `%s` option must be a string array. Option: `%s`.', 'ignore', opts.ignore ) );
8383
}
8484
}
8585
if ( hasOwnProp( options, 'base' ) ) {
8686
opts.base = options.base;
8787
if ( !isString( opts.base ) ) {
88-
return new TypeError( 'invalid option. `base` option must be a primitive string. Option: `' + opts.base + '`.' );
88+
return new TypeError( format( 'invalid option. `%s` option must be a string primitive. Option: `%s`.', 'base', opts.base ) );
8989
}
9090
}
9191
return null;

lib/node_modules/@stdlib/_tools/doctest/create-annotation-value/lib/validate.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ var isPositiveInteger = require( '@stdlib/assert/is-positive-integer' ).isPrimit
2424
var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive;
2525
var isObject = require( '@stdlib/assert/is-plain-object' );
2626
var hasOwnProp = require( '@stdlib/assert/has-own-property' );
27+
var format = require( '@stdlib/string/format' );
2728

2829

2930
// MAIN //
@@ -52,30 +53,30 @@ var hasOwnProp = require( '@stdlib/assert/has-own-property' );
5253
*/
5354
function validate( opts, options ) {
5455
if ( !isObject( options ) ) {
55-
return new TypeError( 'invalid argument. Options argument must be an object. Value: `' + options + '`.' );
56+
return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );
5657
}
5758
if ( hasOwnProp( options, 'decimal' ) ) {
5859
opts.decimal = options.decimal;
5960
if ( !isBoolean( opts.decimal ) ) {
60-
return new TypeError( 'invalid option. `decimal` option must be a boolean primitive. Option: `' + opts.decimal + '`.' );
61+
return new TypeError( format( 'invalid option. `%s` option must be a boolean primitive. Option: `%s`.', 'decimal', opts.decimal ) );
6162
}
6263
}
6364
if ( hasOwnProp( options, 'type' ) ) {
6465
opts.type = options.type;
6566
if ( !isBoolean( opts.type ) ) {
66-
return new TypeError( 'invalid option. `type` option must be a boolean primitive. Option: `' + opts.type + '`.' );
67+
return new TypeError( format( 'invalid option. `%s` option must be a boolean primitive. Option: `%s`.', 'type', opts.type ) );
6768
}
6869
}
6970
if ( hasOwnProp( options, 'numel' ) ) {
7071
opts.numel = options.numel;
7172
if ( !isPositiveInteger( opts.numel ) ) {
72-
return new TypeError( 'invalid option. `numel` option must be a positive integer. Option: `' + opts.numel + '`.' );
73+
return new TypeError( format( 'invalid option. `%s` option must be a positive integer. Option: `%s`.', 'numel', opts.numel ) );
7374
}
7475
}
7576
if ( hasOwnProp( options, 'precision' ) ) {
7677
opts.precision = options.precision;
7778
if ( !isPositiveInteger( opts.precision ) ) {
78-
return new TypeError( 'invalid option. `precision` option must be a positive integer. Option: `' + opts.precision + '`.' );
79+
return new TypeError( format( 'invalid option. `%s` option must be a positive integer. Option: `%s`.', 'precision', opts.precision ) );
7980
}
8081
}
8182
return null;

lib/node_modules/@stdlib/_tools/licenses/header/lib/validate.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ var isObject = require( '@stdlib/assert/is-plain-object' );
2424
var hasOwnProp = require( '@stdlib/assert/has-own-property' );
2525
var isPositiveInteger = require( '@stdlib/assert/is-positive-integer' ).isPrimitive;
2626
var isString = require( '@stdlib/assert/is-string' ).isPrimitive;
27+
var format = require( '@stdlib/string/format' );
2728

2829

2930
// MAIN //
@@ -51,18 +52,18 @@ var isString = require( '@stdlib/assert/is-string' ).isPrimitive;
5152
*/
5253
function validate( opts, options ) {
5354
if ( !isObject( options ) ) {
54-
return new TypeError( 'invalid argument. Options must be an object. Value: `' + options + '`.' );
55+
return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );
5556
}
5657
if ( hasOwnProp( options, 'year' ) ) {
5758
opts.year = options.year;
5859
if ( !isPositiveInteger( opts.year ) ) {
59-
return new TypeError( 'invalid option. `year` option must be a positive integer. Option: `' + opts.year + '`.' );
60+
return new TypeError( format( 'invalid option. `%s` option must be a positive integer. Option: `%s`.', 'year', opts.year ) );
6061
}
6162
}
6263
if ( hasOwnProp( options, 'copyright' ) ) {
6364
opts.copyright = options.copyright;
6465
if ( !isString( opts.copyright ) ) {
65-
return new TypeError( 'invalid option. `copyright` option must be a string primitive. Option: `' + opts.copyright + '`.' );
66+
return new TypeError( format( 'invalid option. `%s` option must be a string primitive. Option: `%s`.', 'copyright', opts.copyright ) );
6667
}
6768
}
6869
return null;

lib/node_modules/@stdlib/_tools/lint/filenames/lib/validate.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
var isObject = require( '@stdlib/assert/is-plain-object' );
2424
var hasOwnProp = require( '@stdlib/assert/has-own-property' );
2525
var isString = require( '@stdlib/assert/is-string' ).isPrimitive;
26+
var format = require( '@stdlib/string/format' );
2627

2728

2829
// MAIN //
@@ -50,19 +51,18 @@ var isString = require( '@stdlib/assert/is-string' ).isPrimitive;
5051
*/
5152
function validate( opts, options ) {
5253
if ( !isObject( options ) ) {
53-
return new TypeError( 'invalid argument. Options argument must be an object. Value: `' + options +
54-
'`.' );
54+
return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );
5555
}
5656
if ( hasOwnProp( options, 'dir' ) ) {
5757
opts.dir = options.dir;
5858
if ( !isString( opts.dir ) ) {
59-
return new TypeError( 'invalid option. `dir` option must be a primitive string. Option: `' + opts.dir + '`.' );
59+
return new TypeError( format( 'invalid option. `%s` option must be a string primitive. Option: `%s`.', 'dir', opts.dir ) );
6060
}
6161
}
6262
if ( hasOwnProp( options, 'pattern' ) ) {
6363
opts.pattern = options.pattern;
6464
if ( !isString( opts.pattern ) ) {
65-
return new TypeError( 'invalid option. `pattern` option must be a primitive string. Option: `' + opts.pattern + '`.' );
65+
return new TypeError( format( 'invalid option. `%s` option must be a string primitive. Option: `%s`.', 'pattern', opts.pattern ) );
6666
}
6767
}
6868
return null;

lib/node_modules/@stdlib/_tools/lint/header-filenames/lib/validate.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
var isObject = require( '@stdlib/assert/is-plain-object' );
2424
var hasOwnProp = require( '@stdlib/assert/has-own-property' );
2525
var isString = require( '@stdlib/assert/is-string' ).isPrimitive;
26+
var format = require( '@stdlib/string/format' );
2627

2728

2829
// MAIN //
@@ -49,13 +50,12 @@ var isString = require( '@stdlib/assert/is-string' ).isPrimitive;
4950
*/
5051
function validate( opts, options ) {
5152
if ( !isObject( options ) ) {
52-
return new TypeError( 'invalid argument. Options argument must be an object. Value: `' + options +
53-
'`.' );
53+
return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );
5454
}
5555
if ( hasOwnProp( options, 'dir' ) ) {
5656
opts.dir = options.dir;
5757
if ( !isString( opts.dir ) ) {
58-
return new TypeError( 'invalid option. `dir` option must be a primitive string. Option: `' + opts.dir + '`.' );
58+
return new TypeError( format( 'invalid option. `%s` option must be a string primitive. Option: `%s`.', 'dir', opts.dir ) );
5959
}
6060
}
6161
return null;

lib/node_modules/@stdlib/_tools/lint/repl-txt/lib/validate.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ var isObject = require( '@stdlib/assert/is-plain-object' );
2424
var hasOwnProp = require( '@stdlib/assert/has-own-property' );
2525
var isString = require( '@stdlib/assert/is-string' ).isPrimitive;
2626
var isStringArray = require( '@stdlib/assert/is-string-array' ).primitives;
27+
var format = require( '@stdlib/string/format' );
2728

2829

2930
// MAIN //
@@ -52,25 +53,24 @@ var isStringArray = require( '@stdlib/assert/is-string-array' ).primitives;
5253
*/
5354
function validate( opts, options ) {
5455
if ( !isObject( options ) ) {
55-
return new TypeError( 'invalid argument. Options argument must be an object. Value: `' + options +
56-
'`.' );
56+
return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );
5757
}
5858
if ( hasOwnProp( options, 'dir' ) ) {
5959
opts.dir = options.dir;
6060
if ( !isString( opts.dir ) ) {
61-
return new TypeError( 'invalid option. `dir` option must be a primitive string. Option: `' + opts.dir + '`.' );
61+
return new TypeError( format( 'invalid option. `%s` option must be a string primitive. Option: `%s`.', 'dir', opts.dir ) );
6262
}
6363
}
6464
if ( hasOwnProp( options, 'pattern' ) ) {
6565
opts.pattern = options.pattern;
6666
if ( !isString( opts.pattern ) ) {
67-
return new TypeError( 'invalid option. `pattern` option must be a primitive string. Option: `' + opts.pattern + '`.' );
67+
return new TypeError( format( 'invalid option. `%s` option must be a string primitive. Option: `%s`.', 'pattern', opts.pattern ) );
6868
}
6969
}
7070
if ( hasOwnProp( options, 'ignore' ) ) {
7171
opts.ignore = options.ignore;
7272
if ( !isStringArray( opts.ignore ) ) {
73-
return new TypeError( 'invalid option. `ignore` option must be a string array. Option: `' + opts.ignore + '`.' );
73+
return new TypeError( format( 'invalid option. `%s` option must be a string array. Option: `%s`.', 'ignore', opts.ignore ) );
7474
}
7575
}
7676
return null;

lib/node_modules/@stdlib/_tools/markdown/inline-svg-equation/lib/validate.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
var hasOwnProp = require( '@stdlib/assert/has-own-property' );
2424
var isObject = require( '@stdlib/assert/is-plain-object' );
2525
var isString = require( '@stdlib/assert/is-string' ).isPrimitive;
26+
var format = require( '@stdlib/string/format' );
2627

2728

2829
// MAIN //
@@ -54,30 +55,30 @@ var isString = require( '@stdlib/assert/is-string' ).isPrimitive;
5455
*/
5556
function validate( opts, options ) {
5657
if ( !isObject( options ) ) {
57-
return new TypeError( 'invalid argument. Options argument must be an object. Value: `' + options + '`.' );
58+
return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );
5859
}
5960
if ( hasOwnProp( options, 'className' ) ) {
6061
opts.className = options.className;
6162
if ( !isString( opts.className ) ) {
62-
return new TypeError( 'invalid option. `className` option must be a string primitive. Option: `' + opts.className + '`.' );
63+
return new TypeError( format( 'invalid option. `%s` option must be a string primitive. Option: `%s`.', 'className', opts.className ) );
6364
}
6465
}
6566
if ( hasOwnProp( options, 'align' ) ) {
6667
opts.align = options.align;
6768
if ( !isString( opts.align ) ) {
68-
return new TypeError( 'invalid option. `align` option must be a string primitive. Option: `' + opts.align + '`.' );
69+
return new TypeError( format( 'invalid option. `%s` option must be a string primitive. Option: `%s`.', 'align', opts.align ) );
6970
}
7071
}
7172
if ( hasOwnProp( options, 'raw' ) ) {
7273
opts.raw = options.raw;
7374
if ( !isString( opts.raw ) ) {
74-
return new TypeError( 'invalid option. `raw` option must be a string primitive. Option: `' + opts.raw + '`.' );
75+
return new TypeError( format( 'invalid option. `%s` option must be a string primitive. Option: `%s`.', 'raw', opts.raw ) );
7576
}
7677
}
7778
if ( hasOwnProp( options, 'label' ) ) {
7879
opts.label = options.label;
7980
if ( !isString( opts.label ) ) {
80-
return new TypeError( 'invalid option. `label` option must be a string primitive. Option: `' + opts.label + '`.' );
81+
return new TypeError( format( 'invalid option. `%s` option must be a string primitive. Option: `%s`.', 'label', opts.label ) );
8182
}
8283
}
8384
return null;

lib/node_modules/@stdlib/_tools/modules/import-require-glob/lib/validate.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
var isObject = require( '@stdlib/assert/is-plain-object' );
2424
var hasOwnProp = require( '@stdlib/assert/has-own-property' );
2525
var isString = require( '@stdlib/assert/is-string' ).isPrimitive;
26+
var format = require( '@stdlib/string/format' );
2627

2728

2829
// MAIN //
@@ -50,19 +51,18 @@ var isString = require( '@stdlib/assert/is-string' ).isPrimitive;
5051
*/
5152
function validate( opts, options ) {
5253
if ( !isObject( options ) ) {
53-
return new TypeError( 'invalid argument. Options argument must be an object. Value: `' + options +
54-
'`.' );
54+
return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );
5555
}
5656
if ( hasOwnProp( options, 'dir' ) ) {
5757
opts.dir = options.dir;
5858
if ( !isString( opts.dir ) ) {
59-
return new TypeError( 'invalid option. `dir` option must be a primitive string. Option: `' + opts.dir + '`.' );
59+
return new TypeError( format( 'invalid option. `%s` option must be a string primitive. Option: `%s`.', 'dir', opts.dir ) );
6060
}
6161
}
6262
if ( hasOwnProp( options, 'pattern' ) ) {
6363
opts.pattern = options.pattern;
6464
if ( !isString( opts.pattern ) ) {
65-
return new TypeError( 'invalid option. `pattern` option must be a primitive string. Option: `' + opts.pattern + '`.' );
65+
return new TypeError( format( 'invalid option. `%s` option must be a string primitive. Option: `%s`.', 'pattern', opts.pattern ) );
6666
}
6767
}
6868
return null;

lib/node_modules/@stdlib/_tools/pkgs/addons/lib/validate.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ var isObject = require( '@stdlib/assert/is-plain-object' );
2424
var hasOwnProp = require( '@stdlib/assert/has-own-property' );
2525
var isString = require( '@stdlib/assert/is-string' ).isPrimitive;
2626
var isStringArray = require( '@stdlib/assert/is-string-array' ).primitives;
27+
var format = require( '@stdlib/string/format' );
2728

2829

2930
// VARIABLES //
@@ -57,28 +58,27 @@ var RE = /package\.json$/;
5758
*/
5859
function validate( opts, options ) {
5960
if ( !isObject( options ) ) {
60-
return new TypeError( 'invalid argument. Options argument must be an object. Value: `' + options +
61-
'`.' );
61+
return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );
6262
}
6363
if ( hasOwnProp( options, 'dir' ) ) {
6464
opts.dir = options.dir;
6565
if ( !isString( opts.dir ) ) {
66-
return new TypeError( 'invalid option. `dir` option must be a primitive string. Option: `' + opts.dir + '`.' );
66+
return new TypeError( format( 'invalid option. `%s` option must be a string primitive. Option: `%s`.', 'dir', opts.dir ) );
6767
}
6868
}
6969
if ( hasOwnProp( options, 'pattern' ) ) {
7070
opts.pattern = options.pattern;
7171
if ( !isString( opts.pattern ) ) {
72-
return new TypeError( 'invalid option. `pattern` option must be a primitive string. Option: `' + opts.pattern + '`.' );
72+
return new TypeError( format( 'invalid option. `%s` option must be a string primitive. Option: `%s`.', 'pattern', opts.pattern ) );
7373
}
7474
if ( !RE.test( opts.pattern ) ) {
75-
return new Error( 'invalid option. `pattern` option must end with `package.json`. Option: `' + opts.pattern +'`.' );
75+
return new Error( format( 'invalid option. `%s` option must end with `package.json`. Option: `%s`.', 'pattern', opts.pattern ) );
7676
}
7777
}
7878
if ( hasOwnProp( options, 'ignore' ) ) {
7979
opts.ignore = options.ignore;
8080
if ( !isStringArray( opts.ignore ) ) {
81-
return new TypeError( 'invalid option. `ignore` option must be a string array. Option: `' + opts.ignore + '`.' );
81+
return new TypeError( format( 'invalid option. `%s` option must be a string array. Option: `%s`.', 'ignore', opts.ignore ) );
8282
}
8383
}
8484
return null;

0 commit comments

Comments
 (0)