Skip to content

Commit 17e8f46

Browse files
committed
Format error messages
1 parent b4195d4 commit 17e8f46

File tree

37 files changed

+165
-129
lines changed

37 files changed

+165
-129
lines changed

lib/node_modules/@stdlib/_tools/licenses/header-regexp-table/lib/main.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ function createTable( license, types ) {
9191
list = EXT;
9292
} else {
9393
if ( !isArray( types ) ) {
94-
throw new TypeError( 'invalid argument. Second argument must be an array. Value: `' + types + '`.' );
94+
throw new TypeError( format( 'invalid argument. Second argument must be an array. Value: `%s`.', types ) );
9595
}
9696
list = types;
9797
}
@@ -106,7 +106,7 @@ function createTable( license, types ) {
106106
}
107107
h = licenseHeader( license, type );
108108
if ( h === null ) {
109-
throw new Error( 'invalid argument. Must provide a supported file type. Value: `' + type + '`.' );
109+
throw new Error( format( 'invalid argument. Must provide a supported file type. Value: `%s`.', type ) );
110110
}
111111
// Remove any surrounding whitespace (e.g., trailing newlines):
112112
h = trim( h );

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ var isString = require( '@stdlib/assert/is-string' ).isPrimitive;
2424
var replace = require( '@stdlib/string/replace' );
2525
var contains = require( '@stdlib/assert/contains' );
2626
var lowercase = require( '@stdlib/string/lowercase' );
27+
var format = require( '@stdlib/string/format' );
2728
var validate = require( './validate.js' );
2829
var licenses = require( './licenses.json' );
2930
var header = require( './header.js' );
@@ -59,10 +60,10 @@ function licenseHeader( license, type, options ) {
5960
var out;
6061

6162
if ( !contains( licenses, license ) ) {
62-
throw new Error( 'invalid argument. Must provide a supported license SPDX identifier. Value: `' + license + '`.' );
63+
throw new Error( format( 'invalid argument. Must provide a supported license SPDX identifier. Value: `%s`.', license ) );
6364
}
6465
if ( !isString( type ) ) {
65-
throw new TypeError( 'invalid argument. Second argument must be a string primitive. Value: `' + type + '`.' );
66+
throw new TypeError( format( 'invalid argument. Second argument must be a string primitive. Value: `%s`.', type ) );
6667
}
6768
opts = {};
6869
if ( arguments.length > 2 ) {

lib/node_modules/@stdlib/_tools/licenses/remove-header-file-list/lib/main.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ var isObject = require( '@stdlib/assert/is-plain-object' );
3232
var isFunction = require( '@stdlib/assert/is-function' );
3333
var readFile = require( '@stdlib/fs/read-file' );
3434
var writeFile = require( '@stdlib/fs/write-file' );
35+
var format = require( '@stdlib/string/format' );
3536
var cwd = require( '@stdlib/process/cwd' );
3637
var extname = require( '@stdlib/utils/extname' );
3738
var nextTick = require( '@stdlib/utils/next-tick' );
@@ -88,21 +89,21 @@ function removeHeader( files, header, clbk ) {
8889

8990
FLG = isEmptyArray( files );
9091
if ( !FLG && !isStringArray( files ) ) {
91-
throw new TypeError( 'invalid argument. First argument must be an array of strings. Value: `' + files + '`.' );
92+
throw new TypeError( format( 'invalid argument. First argument must be an array of strings. Value: `%s`.', files ) );
9293
}
9394
if ( isObject( header ) ) {
9495
keys = objectKeys( header );
9596
for ( i = 0; i < keys.length; i++ ) {
9697
v = header[ keys[i] ];
9798
if ( !isString( v ) && !isRegExp( v ) ) {
98-
throw new TypeError( 'invalid argument. A `header` object must map each filename extension to a license header string or regular expression. `' + keys[i] + ': ' + v + '`. Value: `' + JSON.stringify( header ) + '`.' );
99+
throw new TypeError( format( 'invalid argument. A `header` object must map each filename extension to a license header string or regular expression. `%s: %s`. Value: `%s`.', keys[i], v, JSON.stringify( header ) ) );
99100
}
100101
}
101102
} else if ( !isString( header ) && !isRegExp( header ) ) {
102-
throw new TypeError( 'invalid argument. Second argument must be either a primitive string, a regular expression, or an object whose keys are filename extensions and whose values are header strings or regular expressions. Value: `' + header + '`.' );
103+
throw new TypeError( format( 'invalid argument. Second argument must be either a primitive string, a regular expression, or an object whose keys are filename extensions and whose values are header strings or regular expressions. Value: `%s`.', header ) );
103104
}
104105
if ( !isFunction( clbk ) ) {
105-
throw new TypeError( 'invalid argument. Callback argument must be a function. Value: `' + clbk + '`.' );
106+
throw new TypeError( format( 'invalid argument. Callback argument must be a function. Value: `%s`.', clbk ) );
106107
}
107108
dir = cwd();
108109
debug( 'Current working directory: %s', dir );

lib/node_modules/@stdlib/_tools/licenses/remove-header-file-list/lib/sync.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ var isRegExp = require( '@stdlib/assert/is-regexp' );
3131
var isObject = require( '@stdlib/assert/is-plain-object' );
3232
var readFile = require( '@stdlib/fs/read-file' ).sync;
3333
var writeFile = require( '@stdlib/fs/write-file' ).sync;
34+
var format = require( '@stdlib/string/format' );
3435
var cwd = require( '@stdlib/process/cwd' );
3536
var extname = require( '@stdlib/utils/extname' );
3637
var remove = require( '@stdlib/_tools/licenses/remove-header' );
@@ -84,18 +85,18 @@ function removeHeader( files, header ) {
8485
var i;
8586

8687
if ( !isEmptyArray( files ) && !isStringArray( files ) ) {
87-
throw new TypeError( 'invalid argument. First argument must be an array of strings. Value: `' + files + '`.' );
88+
throw new TypeError( format( 'invalid argument. First argument must be an array of strings. Value: `%s`.', files ) );
8889
}
8990
if ( isObject( header ) ) {
9091
keys = objectKeys( header );
9192
for ( i = 0; i < keys.length; i++ ) {
9293
v = header[ keys[i] ];
9394
if ( !isString( v ) && !isRegExp( v ) ) {
94-
throw new TypeError( 'invalid argument. A `header` object must map each filename extension to a license header string or regular expression. `' + keys[i] + ': ' + v + '`. Value: `' + JSON.stringify( header ) + '`.' );
95+
throw new TypeError( format( 'invalid argument. A `header` object must map each filename extension to a license header string or regular expression. `%s: %s`. Value: `%s`.', keys[i], v, JSON.stringify( header ) ) );
9596
}
9697
}
9798
} else if ( !isString( header ) && !isRegExp( header ) ) {
98-
throw new TypeError( 'invalid argument. Second argument must be either a primitive string, regular expression, or an object whose keys are filename extensions and whose values are header strings or regular expressions. Value: `' + header + '`.' );
99+
throw new TypeError( format( 'invalid argument. Second argument must be either a primitive string, regular expression, or an object whose keys are filename extensions and whose values are header strings or regular expressions. Value: `%s`.', header ) );
99100
}
100101
header = normalizeHeader( header );
101102

lib/node_modules/@stdlib/_tools/licenses/update-header-file-list/lib/main.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ var isObject = require( '@stdlib/assert/is-plain-object' );
3232
var isFunction = require( '@stdlib/assert/is-function' );
3333
var readFile = require( '@stdlib/fs/read-file' );
3434
var writeFile = require( '@stdlib/fs/write-file' );
35+
var format = require( '@stdlib/string/format' );
3536
var cwd = require( '@stdlib/process/cwd' );
3637
var extname = require( '@stdlib/utils/extname' );
3738
var nextTick = require( '@stdlib/utils/next-tick' );
@@ -92,32 +93,32 @@ function updateHeader( files, old, header, clbk ) {
9293

9394
FLG = isEmptyArray( files );
9495
if ( !FLG && !isStringArray( files ) ) {
95-
throw new TypeError( 'invalid argument. First argument must be an array of strings. Value: `' + files + '`.' );
96+
throw new TypeError( format( 'invalid argument. First argument must be an array of strings. Value: `%s`.', files ) );
9697
}
9798
if ( isObject( old ) ) {
9899
keys = objectKeys( old );
99100
for ( i = 0; i < keys.length; i++ ) {
100101
v = old[ keys[i] ];
101102
if ( !isString( v ) && !isRegExp( v ) ) {
102-
throw new TypeError( 'invalid argument. A header object must map each filename extension to a license header string or regular expression. `' + keys[i] + ': ' + v + '`. Value: `' + JSON.stringify( old ) + '`.' );
103+
throw new TypeError( format( 'invalid argument. A header object must map each filename extension to a license header string or regular expression. `%s: %s`. Value: `%s`.', keys[i], v, JSON.stringify( old ) ) );
103104
}
104105
}
105106
} else if ( !isString( old ) && !isRegExp( old ) ) {
106-
throw new TypeError( 'invalid argument. Second argument must be either a primitive string, a regular expression, or an object whose keys are filename extensions and whose values are header strings or regular expressions. Value: `' + old + '`.' );
107+
throw new TypeError( format( 'invalid argument. Second argument must be either a primitive string, a regular expression, or an object whose keys are filename extensions and whose values are header strings or regular expressions. Value: `%s`.', old ) );
107108
}
108109
if ( isObject( header ) ) {
109110
keys = objectKeys( header );
110111
for ( i = 0; i < keys.length; i++ ) {
111112
v = header[ keys[i] ];
112113
if ( !isString( v ) ) {
113-
throw new TypeError( 'invalid argument. A header object must map each filename extension to a license header string. `' + keys[i] + ': ' + v + '`. Value: `' + JSON.stringify( header ) + '`.' );
114+
throw new TypeError( format( 'invalid argument. A header object must map each filename extension to a license header string. `%s: %s`. Value: `%s`.', keys[i], v, JSON.stringify( header ) ) );
114115
}
115116
}
116117
} else if ( !isString( header ) ) {
117-
throw new TypeError( 'invalid argument. Third argument must be either a primitive string or an object whose keys are filename extensions and whose values are header strings. Value: `' + header + '`.' );
118+
throw new TypeError( format( 'invalid argument. Third argument must be either a primitive string or an object whose keys are filename extensions and whose values are header strings. Value: `%s`.', header ) );
118119
}
119120
if ( !isFunction( clbk ) ) {
120-
throw new TypeError( 'invalid argument. Callback argument must be a function. Value: `' + clbk + '`.' );
121+
throw new TypeError( format( 'invalid argument. Callback argument must be a function. Value: `%s`.', clbk ) );
121122
}
122123
dir = cwd();
123124
debug( 'Current working directory: %s', dir );

lib/node_modules/@stdlib/_tools/licenses/update-header-file-list/lib/sync.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ var writeFile = require( '@stdlib/fs/write-file' ).sync;
3434
var cwd = require( '@stdlib/process/cwd' );
3535
var extname = require( '@stdlib/utils/extname' );
3636
var update = require( '@stdlib/_tools/licenses/update-header' );
37+
var format = require( '@stdlib/string/format' );
3738
var normalizeHeader = require( './normalize_header.js' );
3839

3940

@@ -89,29 +90,29 @@ function updateHeader( files, old, header ) {
8990
var i;
9091

9192
if ( !isEmptyArray( files ) && !isStringArray( files ) ) {
92-
throw new TypeError( 'invalid argument. First argument must be an array of strings. Value: `' + files + '`.' );
93+
throw new TypeError( format( 'invalid argument. First argument must be an array of strings. Value: `%s`.', files ) );
9394
}
9495
if ( isObject( old ) ) {
9596
keys = objectKeys( old );
9697
for ( i = 0; i < keys.length; i++ ) {
9798
v = old[ keys[i] ];
9899
if ( !isString( v ) && !isRegExp( v ) ) {
99-
throw new TypeError( 'invalid argument. A header object must map each filename extension to a license header string or regular expression. `' + keys[i] + ': ' + v + '`. Value: `' + JSON.stringify( old ) + '`.' );
100+
throw new TypeError( format( 'invalid argument. A header object must map each filename extension to a license header string or regular expression. `%s: %s`. Value: `%s`.', keys[i], v, JSON.stringify( old ) ) );
100101
}
101102
}
102103
} else if ( !isString( old ) && !isRegExp( old ) ) {
103-
throw new TypeError( 'invalid argument. Second argument must be either a primitive string, a regular expression, or an object whose keys are filename extensions and whose values are header strings or regular expressions. Value: `' + old + '`.' );
104+
throw new TypeError( format( 'invalid argument. Second argument must be either a primitive string, a regular expression, or an object whose keys are filename extensions and whose values are header strings or regular expressions. Value: `%s`.', old ) );
104105
}
105106
if ( isObject( header ) ) {
106107
keys = objectKeys( header );
107108
for ( i = 0; i < keys.length; i++ ) {
108109
v = header[ keys[i] ];
109110
if ( !isString( v ) ) {
110-
throw new TypeError( 'invalid argument. A header object must map each filename extension to a license header string. `' + keys[i] + ': ' + v + '`. Value: `' + JSON.stringify( header ) + '`.' );
111+
throw new TypeError( format( 'invalid argument. A header object must map each filename extension to a license header string. `%s: %s`. Value: `%s`.', keys[i], v, JSON.stringify( header ) ) );
111112
}
112113
}
113114
} else if ( !isString( header ) ) {
114-
throw new TypeError( 'invalid argument. Third argument must be either a primitive string or an object whose keys are filename extensions and whose values are header strings. Value: `' + header + '`.' );
115+
throw new TypeError( format( 'invalid argument. Third argument must be either a primitive string or an object whose keys are filename extensions and whose values are header strings. Value: `%s`.', header ) );
115116
}
116117
old = normalizeHeader( old );
117118
header = normalizeHeader( header );

lib/node_modules/@stdlib/_tools/lint/license-header-file-list/lib/main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ function lint( files, header, clbk ) {
109109
for ( i = 0; i < keys.length; i++ ) {
110110
v = h[ keys[i] ];
111111
if ( !isString( v ) && !isRegExp( v ) ) {
112-
throw new TypeError( 'invalid argument. A `header` object must map each filename extension to a string and/or regular expression. `' + keys[i] + ': ' + v + '`. Value: `' + JSON.stringify( h ) + '`.' );
112+
throw new TypeError( format( 'invalid argument. A `header` object must map each filename extension to a string and/or regular expression. `%s: %s`. Value: `%s`.', keys[i], v, JSON.stringify( h ) ) );
113113
}
114114
}
115115
} else if ( !isString( h ) && !isRegExp( h ) ) {

lib/node_modules/@stdlib/_tools/lint/license-header-file-list/lib/sync.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ var isRegExp = require( '@stdlib/assert/is-regexp' );
3131
var isObject = require( '@stdlib/assert/is-plain-object' );
3232
var readFile = require( '@stdlib/fs/read-file' ).sync;
3333
var extname = require( '@stdlib/utils/extname' );
34+
var format = require( '@stdlib/string/format' );
3435
var cwd = require( '@stdlib/process/cwd' );
3536
var headers = require( '@stdlib/_tools/licenses/header-regexp-table' );
3637
var linter = require( '@stdlib/_tools/lint/license-header' );
@@ -90,7 +91,7 @@ function lint( files, header ) {
9091
var i;
9192

9293
if ( !isEmptyArray( files ) && !isStringArray( files ) ) {
93-
throw new TypeError( 'invalid argument. First argument must be an array of strings. Value: `' + files + '`.' );
94+
throw new TypeError( format( 'invalid argument. First argument must be an array of strings. Value: `%s`.', files ) );
9495
}
9596
if ( arguments.length > 1 ) {
9697
h = header;
@@ -99,11 +100,11 @@ function lint( files, header ) {
99100
for ( i = 0; i < keys.length; i++ ) {
100101
v = h[ keys[i] ];
101102
if ( !isString( v ) && !isRegExp( v ) ) {
102-
throw new TypeError( 'invalid argument. A `header` object must map each filename extension to a string and/or regular expression. `' + keys[i] + ': ' + v + '`. Value: `' + JSON.stringify( h ) + '`.' );
103+
throw new TypeError( format( 'invalid argument. A `header` object must map each filename extension to a string and/or regular expression. `%s: %s`. Value: `%s`.', keys[i], v, JSON.stringify( h ) ) );
103104
}
104105
}
105106
} else if ( !isString( h ) && !isRegExp( h ) ) {
106-
throw new TypeError( 'invalid argument. Second argument must be either a primitive string, regular expression, or an object whose keys are filename extensions and whose values are header strings or regular expressions. Value: `' + h + '`.' );
107+
throw new TypeError( format( 'invalid argument. Second argument must be either a primitive string, regular expression, or an object whose keys are filename extensions and whose values are header strings or regular expressions. Value: `%s`.', h ) );
107108
}
108109
} else {
109110
h = headers( SPDX );

lib/node_modules/@stdlib/_tools/lint/license-header-glob/lib/main.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ var logger = require( 'debug' );
2626
var isFunction = require( '@stdlib/assert/is-function' );
2727
var cwd = require( '@stdlib/process/cwd' );
2828
var copy = require( '@stdlib/utils/copy' );
29+
var format = require( '@stdlib/string/format' );
2930
var linter = require( '@stdlib/_tools/lint/license-header-file-list' );
3031
var DEFAULTS = require( './defaults.js' );
3132
var validate = require( './validate.js' );
@@ -85,7 +86,7 @@ function lint() {
8586
}
8687
}
8788
if ( !isFunction( clbk ) ) {
88-
throw new TypeError( 'invalid argument. Callback argument must be a function. Value: `' + clbk + '`.' );
89+
throw new TypeError( format( 'invalid argument. Callback argument must be a function. Value: `%s`.', clbk ) );
8990
}
9091
debug( 'Options: %s', JSON.stringify( opts ) );
9192
if ( opts.dir ) {

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ var hasOwnProp = require( '@stdlib/assert/has-own-property' );
2626
var isString = require( '@stdlib/assert/is-string' ).isPrimitive;
2727
var isStringArray = require( '@stdlib/assert/is-string-array' ).primitives;
2828
var isRegExp = require( '@stdlib/assert/is-regexp' );
29+
var format = require( '@stdlib/string/format' );
2930

3031

3132
// MAIN //
@@ -58,25 +59,24 @@ function validate( opts, options ) {
5859
var v;
5960
var i;
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
}
7676
if ( hasOwnProp( options, 'ignore' ) ) {
7777
opts.ignore = options.ignore;
7878
if ( !isStringArray( opts.ignore ) ) {
79-
return new TypeError( 'invalid option. `ignore` option must be a string array. Option: `' + opts.ignore + '`.' );
79+
return new TypeError( format( 'invalid option. `%s` option must be a string array. Option: `%s`.', 'ignore', opts.ignore ) );
8080
}
8181
}
8282
if ( hasOwnProp( options, 'header' ) ) {
@@ -86,11 +86,11 @@ function validate( opts, options ) {
8686
for ( i = 0; i < keys.length; i++ ) {
8787
v = opts.header[ keys[i] ];
8888
if ( !isString( v ) && !isRegExp( v ) ) {
89-
return new TypeError( 'invalid option. A `header` option object must map each filename extension to a string and/or regular expression. `' + keys[i] + ': ' + v + '`. Value: `' + JSON.stringify( opts.header ) + '`.' );
89+
return new TypeError( format( 'invalid option. A `header` option object must map each filename extension to a string and/or regular expression. `%s: %s`. Value: `%s`.', keys[i], v, JSON.stringify( opts.header ) ) );
9090
}
9191
}
9292
} else if ( !isString( opts.header ) && !isRegExp( opts.header ) ) {
93-
return new TypeError( 'invalid option. `header` option must be either a primitive string, regular expression, or an object whose keys are filename extensions and whose values are header strings or regular expressions. Option: `' + opts.header + '`.' );
93+
return new TypeError( format( 'invalid option. `%s` option must be either a primitive string, regular expression, or an object whose keys are filename extensions and whose values are header strings or regular expressions. Option: `%s`.', 'header', opts.header ) );
9494
}
9595
}
9696
return null;

0 commit comments

Comments
 (0)