Skip to content

Commit 04164c1

Browse files
committed
Format error messages
1 parent ff308e9 commit 04164c1

File tree

54 files changed

+155
-104
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+155
-104
lines changed

lib/node_modules/@stdlib/_tools/benchmarks/browser-build/lib/validate.js

Lines changed: 7 additions & 7 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 //
@@ -53,37 +54,36 @@ var isString = require( '@stdlib/assert/is-string' ).isPrimitive;
5354
*/
5455
function validate( opts, options ) {
5556
if ( !isObject( options ) ) {
56-
return new TypeError( 'invalid argument. Options argument must be an object. Value: `' + options +
57-
'`.' );
57+
return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );
5858
}
5959
if ( hasOwnProp( options, 'pattern' ) ) {
6060
opts.pattern = options.pattern;
6161
if ( !isString( opts.pattern ) ) {
62-
return new TypeError( 'invalid option. `pattern` option must be a string. Option: `'+opts.pattern+'`.' );
62+
return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'pattern', opts.pattern ) );
6363
}
6464
}
6565
if ( hasOwnProp( options, 'bundle' ) ) {
6666
opts.bundle = options.bundle;
6767
if ( !isString( opts.bundle ) ) {
68-
return new TypeError( 'invalid option. `bundle` option must be a string. Option: `'+opts.bundle+'`.' );
68+
return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'bundle', opts.bundle ) );
6969
}
7070
}
7171
if ( hasOwnProp( options, 'mount' ) ) {
7272
opts.mount = options.mount;
7373
if ( !isString( opts.mount ) ) {
74-
return new TypeError( 'invalid option. `mount` option must be a string. Option: `'+opts.mount+'`.' );
74+
return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'mount', opts.mount ) );
7575
}
7676
}
7777
if ( hasOwnProp( options, 'html' ) ) {
7878
opts.html = options.html;
7979
if ( !isString( opts.html ) ) {
80-
return new TypeError( 'invalid option. `html` option must be a string. Option: `'+opts.html+'`.' );
80+
return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'html', opts.html ) );
8181
}
8282
}
8383
if ( hasOwnProp( options, 'title' ) ) {
8484
opts.title = options.title;
8585
if ( !isString( opts.title ) ) {
86-
return new TypeError( 'invalid option. `title` option must be a string. Option: `'+opts.title+'`.' );
86+
return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'title', opts.title ) );
8787
}
8888
}
8989
return null;

lib/node_modules/@stdlib/_tools/benchmarks/bundle/lib/validate.js

Lines changed: 4 additions & 4 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 //
@@ -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, 'out' ) ) {
5757
opts.out = options.out;
5858
if ( !isString( opts.out ) ) {
59-
return new TypeError( 'invalid option. `out` option must be a string. Option: `'+opts.out+'`.' );
59+
return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'out', opts.out ) );
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 string. Option: `'+opts.pattern+'`.' );
65+
return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'pattern', opts.pattern ) );
6666
}
6767
}
6868
return null;

lib/node_modules/@stdlib/_tools/browserify/string/lib/validate.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ var isString = require( '@stdlib/assert/is-string' ).isPrimitive;
2626
var isArray = require( '@stdlib/assert/is-array' );
2727
var isStringArray = require( '@stdlib/assert/is-string-array' ).primitives;
2828
var objectKeys = require( '@stdlib/utils/keys' );
29+
var format = require( '@stdlib/string/format' );
2930

3031

3132
// VARIABLES //
@@ -71,42 +72,42 @@ function validate( opts, options ) {
7172
var k;
7273
var i;
7374
if ( !isObject( options ) ) {
74-
return new TypeError( 'invalid argument. Options must be an object. Value: `' + options + '`.' );
75+
return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );
7576
}
7677
if ( hasOwnProp( options, 'requireName' ) ) {
7778
opts.externalRequireName = options.requireName;
7879
if ( !isString( opts.externalRequireName ) ) {
79-
return new TypeError( 'invalid option. `requireName` option must be a string. Option: `' + opts.externalRequireName + '`.' );
80+
return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'requireName', opts.externalRequireName ) );
8081
}
8182
}
8283
if ( hasOwnProp( options, 'exportName' ) ) {
8384
opts.exportName = options.exportName;
8485
if ( !isString( opts.exportName ) ) {
85-
return new TypeError( 'invalid option. `exportName` option must be a string. Option: `' + opts.exportName + '`.' );
86+
return new TypeError( format( 'invalid option. `%s` option must be a string primitive. Option: `%s`.', 'exportName', opts.exportName ) );
8687
}
8788
}
8889
if ( hasOwnProp( options, 'standalone' ) ) {
8990
opts.standalone = options.standalone;
9091
if ( !isString( opts.standalone ) ) {
91-
return new TypeError( 'invalid option. `standalone` option must be a string. Option: `' + opts.standalone + '`.' );
92+
return new TypeError( format( 'invalid option. `%s` option must be a string primitive. Option: `%s`.', 'standalone', opts.standalone ) );
9293
}
9394
}
9495
if ( hasOwnProp( options, 'transforms' ) ) {
9596
opts.transforms = options.transforms;
9697
if ( !isArray( opts.transforms ) ) {
97-
return new TypeError( 'invalid option. `transforms` option must be an array. Option: `' + opts.transforms + '`.' );
98+
return new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'transforms', opts.transforms ) );
9899
}
99100
}
100101
if ( hasOwnProp( options, 'plugins' ) ) {
101102
opts.plugins = options.plugins;
102103
if ( !isArray( opts.plugins ) ) {
103-
return new TypeError( 'invalid option. `plugins` option must be an array. Option: `' + opts.plugins + '`.' );
104+
return new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'plugins', opts.plugins ) );
104105
}
105106
}
106107
if ( hasOwnProp( options, 'external' ) ) {
107108
opts.external = options.external;
108109
if ( !isStringArray( opts.external ) ) {
109-
return new TypeError( 'invalid option. `external` option must be an array of strings. Option: `' + opts.external + '`.' );
110+
return new TypeError( format( 'invalid option. `%s` option must be an array of strings. Option: `%s`.', 'external', opts.external ) );
110111
}
111112
}
112113
// Merge any remaining options...

lib/node_modules/@stdlib/_tools/github/subscriptions/lib/factory.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
// MODULES //
2222

2323
var isFunction = require( '@stdlib/assert/is-function' );
24+
var format = require( '@stdlib/string/format' );
2425
var merge = require( '@stdlib/utils/merge' );
2526
var request = require( '@stdlib/_tools/github/get' ).factory;
2627
var validate = require( './validate.js' );
@@ -50,7 +51,7 @@ function factory( options, clbk ) {
5051
throw err;
5152
}
5253
if ( !isFunction( clbk ) ) {
53-
throw new TypeError( 'invalid argument. Callback argument must be a function. Value: `' + clbk + '`.' );
54+
throw new TypeError( format( 'invalid argument. Callback argument must be a function. Value: `%s`.', clbk ) );
5455
}
5556
if (
5657
opts.token === void 0 &&

lib/node_modules/@stdlib/_tools/github/workflow-runs/lib/factory.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
// MODULES //
2222

2323
var isFunction = require( '@stdlib/assert/is-function' );
24+
var format = require( '@stdlib/string/format' );
2425
var merge = require( '@stdlib/utils/merge' );
2526
var request = require( '@stdlib/_tools/github/get' ).factory;
2627
var validate = require( './validate.js' );
@@ -53,7 +54,7 @@ function factory( options, clbk ) {
5354
throw err;
5455
}
5556
if ( !isFunction( clbk ) ) {
56-
throw new TypeError( 'invalid argument. Callback argument must be a function. Value: `' + clbk + '`.' );
57+
throw new TypeError( format( 'invalid argument. Callback argument must be a function. Value: `%s`.', clbk ) );
5758
}
5859
opts.pathname += 'repos/'+opts.slug+'/actions/runs';
5960
if ( opts.actor ) {

lib/node_modules/@stdlib/_tools/links/create/lib/async.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ var instanceOf = require( '@stdlib/assert/instance-of' );
2626
var isFunction = require( '@stdlib/assert/is-function' );
2727
var readJSON = require( '@stdlib/fs/read-json' );
2828
var writeFile = require( '@stdlib/fs/write-file' );
29+
var format = require( '@stdlib/string/format' );
2930
var cwd = require( '@stdlib/process/cwd' );
3031
var config = require( './defaults.js' );
3132
var validate = require( './validate.js' );
@@ -86,7 +87,7 @@ function create( options, clbk ) {
8687
throw err;
8788
}
8889
if ( !isFunction( clbk ) ) {
89-
throw new TypeError( 'invalid argument. Last argument must be a function. Value: `'+clbk+'`.' );
90+
throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', clbk ) );
9091
}
9192
opts.database = resolve( cwd(), opts.database );
9293
debug( 'Link details: %s', JSON.stringify( opts ) );

lib/node_modules/@stdlib/_tools/links/id2uri/lib/async.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ var objectKeys = require( '@stdlib/utils/keys' );
2525
var isString = require( '@stdlib/assert/is-string' ).isPrimitive;
2626
var isFunction = require( '@stdlib/assert/is-function' );
2727
var readJSON = require( '@stdlib/fs/read-json' );
28+
var format = require( '@stdlib/string/format' );
2829
var cwd = require( '@stdlib/process/cwd' );
2930
var config = require( './defaults.js' );
3031
var validate = require( './validate.js' );
@@ -61,7 +62,7 @@ function id2uri( id, options, clbk ) {
6162
var err;
6263
var cb;
6364
if ( !isString( id ) ) {
64-
throw new TypeError( 'invalid argument. First argument must be a string. Value: `'+id+'`.' );
65+
throw new TypeError( format( 'invalid argument. First argument must be a string primitive. Value: `%1`.', id ) );
6566
}
6667
opts = {
6768
'database': config.database
@@ -76,7 +77,7 @@ function id2uri( id, options, clbk ) {
7677
cb = clbk;
7778
}
7879
if ( !isFunction( cb ) ) {
79-
throw new TypeError( 'invalid argument. Last argument must be a function. Value: `'+cb+'`.' );
80+
throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', cb ) );
8081
}
8182
opts.database = resolve( cwd(), opts.database );
8283
fopts = {

lib/node_modules/@stdlib/_tools/links/id2uri/lib/sync.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ var objectKeys = require( '@stdlib/utils/keys' );
2525
var isString = require( '@stdlib/assert/is-string' ).isPrimitive;
2626
var readJSON = require( '@stdlib/fs/read-json' ).sync;
2727
var instanceOf = require( '@stdlib/assert/instance-of' );
28+
var format = require( '@stdlib/string/format' );
2829
var cwd = require( '@stdlib/process/cwd' );
2930
var config = require( './defaults.js' );
3031
var validate = require( './validate.js' );
@@ -55,7 +56,7 @@ function id2uri( id, options ) {
5556
var db;
5657
var i;
5758
if ( !isString( id ) ) {
58-
throw new TypeError( 'invalid argument. First argument must be a string. Value: `'+id+'`.' );
59+
throw new TypeError( format( 'invalid argument. First argument must be a string primitive. Value: `%1`.', id ) );
5960
}
6061
opts = {
6162
'database': config.database

lib/node_modules/@stdlib/_tools/links/uri2id/lib/async.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ var isURI = require( '@stdlib/assert/is-uri' );
2525
var isFunction = require( '@stdlib/assert/is-function' );
2626
var readJSON = require( '@stdlib/fs/read-json' );
2727
var hasOwnProp = require( '@stdlib/assert/has-own-property' );
28+
var format = require( '@stdlib/string/format' );
2829
var cwd = require( '@stdlib/process/cwd' );
2930
var config = require( './defaults.js' );
3031
var validate = require( './validate.js' );
@@ -61,7 +62,7 @@ function uri2id( uri, options, clbk ) {
6162
var err;
6263
var cb;
6364
if ( !isURI( uri ) ) {
64-
throw new TypeError( 'invalid argument. First argument must be a URI. Value: `'+uri+'`.' );
65+
throw new TypeError( format( 'invalid argument. First argument must be a URI. Value: `%s`.', uri ) );
6566
}
6667
opts = {
6768
'database': config.database
@@ -76,7 +77,7 @@ function uri2id( uri, options, clbk ) {
7677
cb = clbk;
7778
}
7879
if ( !isFunction( cb ) ) {
79-
throw new TypeError( 'invalid argument. Last argument must be a function. Value: `'+cb+'`.' );
80+
throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', cb ) );
8081
}
8182
opts.database = resolve( cwd(), opts.database );
8283
fopts = {

lib/node_modules/@stdlib/_tools/links/uri2id/lib/sync.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ var isURI = require( '@stdlib/assert/is-uri' );
2525
var readJSON = require( '@stdlib/fs/read-json' ).sync;
2626
var hasOwnProp = require( '@stdlib/assert/has-own-property' );
2727
var instanceOf = require( '@stdlib/assert/instance-of' );
28+
var format = require( '@stdlib/string/format' );
2829
var cwd = require( '@stdlib/process/cwd' );
2930
var config = require( './defaults.js' );
3031
var validate = require( './validate.js' );
@@ -53,7 +54,7 @@ function uri2id( uri, options ) {
5354
var err;
5455
var db;
5556
if ( !isURI( uri ) ) {
56-
throw new TypeError( 'invalid argument. First argument must be a URI. Value: `'+uri+'`.' );
57+
throw new TypeError( format( 'invalid argument. First argument must be a URI. Value: `%s`.', uri ) );
5758
}
5859
opts = {
5960
'database': config.database

0 commit comments

Comments
 (0)