Skip to content

Commit 1c7517b

Browse files
committed
Format error messages
1 parent 249d2b2 commit 1c7517b

File tree

55 files changed

+202
-149
lines changed

Some content is hidden

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

55 files changed

+202
-149
lines changed

lib/node_modules/@stdlib/_tools/modules/pkg-deps/lib/async.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ var isFunction = require( '@stdlib/assert/is-function' );
2828
var copy = require( '@stdlib/utils/copy' );
2929
var cwd = require( '@stdlib/process/cwd' );
3030
var dirname = require( '@stdlib/utils/dirname' );
31+
var format = require( '@stdlib/string/format' );
3132
var defaults = require( './defaults.json' );
3233
var validate = require( './validate.js' );
3334
var walkFile = require( './walk_file.js' );
@@ -89,7 +90,7 @@ function pkgDeps( files, options, clbk ) {
8990
!isStr &&
9091
!isStringArray( files )
9192
) {
92-
throw new TypeError( 'invalid argument. First argument must be either a string or string array. Value: `' + files + '`.' );
93+
throw new TypeError( format( 'invalid argument. First argument must be either a string or string array. Value: `%s`.', files ) );
9394
}
9495
if ( isStr ) {
9596
list = [ files ];
@@ -107,7 +108,7 @@ function pkgDeps( files, options, clbk ) {
107108
}
108109
}
109110
if ( !isFunction( cb ) ) {
110-
throw new TypeError( 'invalid argument. Callback argument must be a function. Value: `' + cb + '`.' );
111+
throw new TypeError( format( 'invalid argument. Callback argument must be a function. Value: `%s`.', cb ) );
111112
}
112113
debug( 'Options: %s', JSON.stringify( opts ) );
113114
aliases = opts.aliases;

lib/node_modules/@stdlib/_tools/pkgs/entry-points/lib/async.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ var path = require( 'path' );
2424
var logger = require( 'debug' );
2525
var isStringArray = require( '@stdlib/assert/is-string-array' ).primitives;
2626
var isFunction = require( '@stdlib/assert/is-function' );
27+
var format = require( '@stdlib/string/format' );
2728
var cwd = require( '@stdlib/process/cwd' );
2829
var copy = require( '@stdlib/utils/copy' );
2930
var defaults = require( './defaults.json' );
@@ -69,7 +70,7 @@ function entryPoints( pkgs, options, clbk ) {
6970
var dir;
7071
var cb;
7172
if ( !isStringArray( pkgs ) ) {
72-
throw new TypeError( 'invalid argument. First argument must be a string array. Value: `' + pkgs + '`.' );
73+
throw new TypeError( format( 'invalid argument. First argument must be a string array. Value: `%s`.', pkgs ) );
7374
}
7475
opts = copy( defaults );
7576
if ( arguments.length < 3 ) {
@@ -82,7 +83,7 @@ function entryPoints( pkgs, options, clbk ) {
8283
}
8384
}
8485
if ( !isFunction( cb ) ) {
85-
throw new TypeError( 'invalid argument. Callback argument must be a function. Value: `' + cb + '`.' );
86+
throw new TypeError( format( 'invalid argument. Callback argument must be a function. Value: `%s`.', cb ) );
8687
}
8788
debug( 'Options: %s', JSON.stringify( opts ) );
8889
if ( opts.dir ) {

lib/node_modules/@stdlib/_tools/search/pkg-index/lib/main.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ var path = require( 'path' );
2424
var logger = require( 'debug' );
2525
var readFileList = require( '@stdlib/fs/read-file-list' );
2626
var isFunction = require( '@stdlib/assert/is-function' );
27+
var format = require( '@stdlib/string/format' );
2728
var copy = require( '@stdlib/utils/copy' );
2829
var cwd = require( '@stdlib/process/cwd' );
2930
var findReadmes = require( '@stdlib/_tools/pkgs/readmes' );
@@ -88,7 +89,7 @@ function pkgIndex() {
8889
}
8990
}
9091
if ( !isFunction( clbk ) ) {
91-
throw new TypeError( 'invalid argument. Callback argument must be a function. Value: `' + clbk + '`.' );
92+
throw new TypeError( format( 'invalid argument. Callback argument must be a function. Value: `%s`.', clbk ) );
9293
}
9394
if ( opts.dir ) {
9495
opts.dir = path.resolve( cwd(), opts.dir );

lib/node_modules/@stdlib/_tools/static-analysis/js/lloc-file-list/lib/main.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ var resolve = require( 'path' ).resolve;
2424
var logger = require( 'debug' );
2525
var isStringArray = require( '@stdlib/assert/is-string-array' ).primitives;
2626
var isFunction = require( '@stdlib/assert/is-function' );
27+
var format = require( '@stdlib/string/format' );
2728
var lloc = require( '@stdlib/_tools/static-analysis/js/lloc' );
2829
var incrlloc = require( '@stdlib/_tools/static-analysis/js/incr/lloc' );
2930
var readFile = require( '@stdlib/fs/read-file' );
@@ -77,7 +78,7 @@ function analyze( files, options, clbk ) {
7778
var dir;
7879
var cb;
7980
if ( !isStringArray( files ) ) {
80-
throw new TypeError( 'invalid argument. First argument must be a list of file paths. Value: `' + files + '`.' );
81+
throw new TypeError( format( 'invalid argument. First argument must be a list of file paths. Value: `%s`.', files ) );
8182
}
8283
nfiles = files.length;
8384
debug( 'Files: %s', files.join( ', ' ) );
@@ -97,7 +98,7 @@ function analyze( files, options, clbk ) {
9798
cb = options;
9899
}
99100
if ( !isFunction( cb ) ) {
100-
throw new TypeError( 'invalid argument. Callback argument must be a function. Value: `' + cb + '`.' );
101+
throw new TypeError( format( 'invalid argument. Callback argument must be a function. Value: `%s`.', cb ) );
101102
}
102103
debug( 'Options: %s', JSON.stringify( opts ) );
103104

lib/node_modules/@stdlib/_tools/static-analysis/js/program-summary/lib/main.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
var parse = require( 'acorn' ).parse;
2424
var isString = require( '@stdlib/assert/is-string' ).isPrimitive;
2525
var isBuffer = require( '@stdlib/assert/is-buffer' );
26+
var format = require( '@stdlib/string/format' );
2627
var copy = require( '@stdlib/utils/copy' );
2728
var RE_EOL = require( '@stdlib/regexp/eol' ).REGEXP;
2829
var DEFAULTS = require( './defaults.json' );
@@ -60,7 +61,7 @@ function summary( input ) {
6061
var ast;
6162

6263
if ( !isString( input ) && !isBuffer( input ) ) {
63-
throw new TypeError( 'invalid argument. Must provide either a string or a Buffer. Value: `' + input + '`.' );
64+
throw new TypeError( format( 'invalid argument. Must provide either a string or a Buffer. Value: `%s`.', input ) );
6465
}
6566
// Ensure that provided input is a `string`:
6667
input = input.toString();

lib/node_modules/@stdlib/_tools/static-analysis/js/sloc-file-list/lib/main.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ var isFunction = require( '@stdlib/assert/is-function' );
2727
var sloc = require( '@stdlib/_tools/static-analysis/js/sloc' );
2828
var incrsloc = require( '@stdlib/_tools/static-analysis/js/incr/sloc' );
2929
var readFile = require( '@stdlib/fs/read-file' );
30+
var format = require( '@stdlib/string/format' );
3031
var cwd = require( '@stdlib/process/cwd' );
3132
var defaults = require( './defaults.json' );
3233
var validate = require( './validate.js' );
@@ -77,7 +78,7 @@ function analyze( files, options, clbk ) {
7778
var dir;
7879
var cb;
7980
if ( !isStringArray( files ) ) {
80-
throw new TypeError( 'invalid argument. First argument must be a list of file paths. Value: `' + files + '`.' );
81+
throw new TypeError( format( 'invalid argument. First argument must be a list of file paths. Value: `%s`.', files ) );
8182
}
8283
nfiles = files.length;
8384
debug( 'Files: %s', files.join( ', ' ) );
@@ -97,7 +98,7 @@ function analyze( files, options, clbk ) {
9798
cb = options;
9899
}
99100
if ( !isFunction( cb ) ) {
100-
throw new TypeError( 'invalid argument. Callback argument must be a function. Value: `' + cb + '`.' );
101+
throw new TypeError( format( 'invalid argument. Callback argument must be a function. Value: `%s`.', cb ) );
101102
}
102103
debug( 'Options: %s', JSON.stringify( opts ) );
103104

lib/node_modules/@stdlib/_tools/static-analysis/js/sloc-glob/lib/main.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ var logger = require( 'debug' );
2525
var glob = require( 'glob' );
2626
var copy = require( '@stdlib/utils/copy' );
2727
var isFunction = require( '@stdlib/assert/is-function' );
28+
var format = require( '@stdlib/string/format' );
2829
var sloc = require( '@stdlib/_tools/static-analysis/js/sloc-file-list' );
2930
var cwd = require( '@stdlib/process/cwd' );
3031
var defaults = require( './defaults.json' );
@@ -87,7 +88,7 @@ function analyze( options, clbk ) {
8788
cb = clbk;
8889
}
8990
if ( !isFunction( cb ) ) {
90-
throw new TypeError( 'invalid argument. Callback argument must be a function. Value: `' + cb + '`.' );
91+
throw new TypeError( format( 'invalid argument. Callback argument must be a function. Value: `%s`.', cb ) );
9192
}
9293
debug( 'Options: %s', JSON.stringify( opts ) );
9394

lib/node_modules/@stdlib/_tools/static-analysis/js/summarize-file-list/lib/main.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ var isFunction = require( '@stdlib/assert/is-function' );
2727
var summary = require( '@stdlib/_tools/static-analysis/js/program-summary' );
2828
var incrsummary = require( '@stdlib/_tools/static-analysis/js/incr/program-summary' );
2929
var readFile = require( '@stdlib/fs/read-file' );
30+
var format = require( '@stdlib/string/format' );
3031
var cwd = require( '@stdlib/process/cwd' );
3132
var defaults = require( './defaults.json' );
3233
var validate = require( './validate.js' );
@@ -77,7 +78,7 @@ function analyze( files, options, clbk ) {
7778
var dir;
7879
var cb;
7980
if ( !isStringArray( files ) ) {
80-
throw new TypeError( 'invalid argument. First argument must be a list of file paths. Value: `' + files + '`.' );
81+
throw new TypeError( format( 'invalid argument. First argument must be a list of file paths. Value: `%s`.', files ) );
8182
}
8283
nfiles = files.length;
8384
debug( 'Files: %s', files.join( ', ' ) );
@@ -97,7 +98,7 @@ function analyze( files, options, clbk ) {
9798
cb = options;
9899
}
99100
if ( !isFunction( cb ) ) {
100-
throw new TypeError( 'invalid argument. Callback argument must be a function. Value: `' + cb + '`.' );
101+
throw new TypeError( format( 'invalid argument. Callback argument must be a function. Value: `%s`.', cb ) );
101102
}
102103
debug( 'Options: %s', JSON.stringify( opts ) );
103104

lib/node_modules/@stdlib/_tools/static-analysis/js/summarize-file-list/lib/sync.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ var isStringArray = require( '@stdlib/assert/is-string-array' ).primitives;
2626
var summary = require( '@stdlib/_tools/static-analysis/js/program-summary' );
2727
var incrsummary = require( '@stdlib/_tools/static-analysis/js/incr/program-summary' );
2828
var readFileSync = require( '@stdlib/fs/read-file' ).sync;
29+
var format = require( '@stdlib/string/format' );
2930
var cwd = require( '@stdlib/process/cwd' );
3031
var defaults = require( './defaults.json' );
3132
var validate = require( './validate.js' );
@@ -71,7 +72,7 @@ function analyze( files, options ) {
7172
var dir;
7273
var i;
7374
if ( !isStringArray( files ) ) {
74-
throw new TypeError( 'invalid argument. First argument must be a list of file paths. Value: `' + files + '`.' );
75+
throw new TypeError( format( 'invalid argument. First argument must be a list of file paths. Value: `%s`.', files ) );
7576
}
7677
nfiles = files.length;
7778
debug( 'Files: %s', files.join( ', ' ) );

lib/node_modules/@stdlib/_tools/static-analysis/js/summarize-glob/lib/main.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ var glob = require( 'glob' );
2626
var copy = require( '@stdlib/utils/copy' );
2727
var isFunction = require( '@stdlib/assert/is-function' );
2828
var summarize = require( '@stdlib/_tools/static-analysis/js/summarize-file-list' );
29+
var format = require( '@stdlib/string/format' );
2930
var cwd = require( '@stdlib/process/cwd' );
3031
var defaults = require( './defaults.json' );
3132
var validate = require( './validate.js' );
@@ -86,7 +87,7 @@ function analyze( options, clbk ) {
8687
cb = clbk;
8788
}
8889
if ( !isFunction( cb ) ) {
89-
throw new TypeError( 'invalid argument. Callback argument must be a function. Value: `' + cb + '`.' );
90+
throw new TypeError( format( 'invalid argument. Callback argument must be a function. Value: `%s`.', cb ) );
9091
}
9192
debug( 'Options: %s', JSON.stringify( opts ) );
9293

lib/node_modules/@stdlib/complex/base/wrap-function/lib/main.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
var isFunction = require( '@stdlib/assert/is-function' );
2626
var isNonNegativeInteger = require( '@stdlib/assert/is-nonnegative-integer' ).isPrimitive;
27+
var format = require( '@stdlib/string/format' );
2728

2829

2930
// VARIABLES //
@@ -71,13 +72,13 @@ var T = 'number';
7172
function wrap( fcn, nargs, ctor ) {
7273
var fcns;
7374
if ( !isFunction( fcn ) ) {
74-
throw new TypeError( 'invalid argument. First argument must be a function. Value: `' + fcn + '`.' );
75+
throw new TypeError( format( 'invalid argument. First argument must be a function. Value: `%s`.', fcn ) );
7576
}
7677
if ( !isNonNegativeInteger( nargs ) ) {
77-
throw new TypeError( 'invalid argument. Second argument must be a nonnegative integer. Value: `' + nargs + '`.' );
78+
throw new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', nargs ) );
7879
}
7980
if ( !isFunction( ctor ) ) {
80-
throw new TypeError( 'invalid argument. Third argument must be a constructor function. Value: `' + ctor + '`.' );
81+
throw new TypeError( format( 'invalid argument. Third argument must be a constructor function. Value: `%s`.', ctor ) );
8182
}
8283
fcns = [ fcn0, fcn1, fcn2, fcn3, fcn4, fcn5 ];
8384
return ( nargs <= 5 ) ? fcns[ nargs ] : fcnN;

lib/node_modules/@stdlib/complex/cmplx/lib/complex.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
// MODULES //
2222

23+
var format = require( '@stdlib/string/format' );
2324
var CTORS = require( './ctors.js' );
2425

2526

@@ -45,7 +46,7 @@ function complex( real, imag, dtype ) {
4546
if ( ctor ) {
4647
return new ctor( real, imag );
4748
}
48-
throw new TypeError( 'invalid argument. Must provide a recognized data type. Value: `'+dtype+'`.' );
49+
throw new TypeError( format( 'invalid argument. Must provide a recognized data type. Value: `%s`.', dtype ) );
4950
}
5051
return new CTORS[ 'float64' ]( real, imag );
5152
}

lib/node_modules/@stdlib/complex/float32/lib/main.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ var isNumber = require( '@stdlib/assert/is-number' ).isPrimitive;
2424
var defineProperty = require( '@stdlib/utils/define-property' );
2525
var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' );
2626
var float64ToFloat32 = require( '@stdlib/number/float64/base/to-float32' );
27+
var format = require( '@stdlib/string/format' );
2728
var toStr = require( './tostring.js' );
2829
var toJSON = require( './tojson.js' );
2930

@@ -50,10 +51,10 @@ function Complex64( real, imag ) {
5051
throw new TypeError( 'invalid invocation. Constructor must be called with the `new` keyword.' );
5152
}
5253
if ( !isNumber( real ) ) {
53-
throw new TypeError( 'invalid argument. Real component must be a number primitive. Value: `'+real+'`.' );
54+
throw new TypeError( format( 'invalid argument. Real component must be a number primitive. Value: `%s`.', real ) );
5455
}
5556
if ( !isNumber( imag ) ) {
56-
throw new TypeError( 'invalid argument. Imaginary component must be a number primitive. Value: `'+imag+'`.' );
57+
throw new TypeError( format( 'invalid argument. Imaginary component must be a number primitive. Value: `%s`.', imag ) );
5758
}
5859
defineProperty( this, 're', {
5960
'configurable': false,

lib/node_modules/@stdlib/complex/float64/lib/main.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
var isNumber = require( '@stdlib/assert/is-number' ).isPrimitive;
2424
var defineProperty = require( '@stdlib/utils/define-property' );
2525
var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' );
26+
var format = require( '@stdlib/string/format' );
2627
var toStr = require( './tostring.js' );
2728
var toJSON = require( './tojson.js' );
2829

@@ -49,10 +50,10 @@ function Complex128( real, imag ) {
4950
throw new TypeError( 'invalid invocation. Constructor must be called with the `new` keyword.' );
5051
}
5152
if ( !isNumber( real ) ) {
52-
throw new TypeError( 'invalid argument. Real component must be a number primitive. Value: `'+real+'`.' );
53+
throw new TypeError( format( 'invalid argument. Real component must be a number primitive. Value: `%s`.', real ) );
5354
}
5455
if ( !isNumber( imag ) ) {
55-
throw new TypeError( 'invalid argument. Imaginary component must be a number primitive. Value: `'+imag+'`.' );
56+
throw new TypeError( format( 'invalid argument. Imaginary component must be a number primitive. Value: `%s`.', imag ) );
5657
}
5758
defineProperty( this, 're', {
5859
'configurable': false,

lib/node_modules/@stdlib/ndarray/base/from-scalar/lib/main.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
var arraylike2object = require( '@stdlib/array/base/arraylike2object' );
2424
var buffer = require( '@stdlib/ndarray/base/buffer' );
2525
var ndarray = require( '@stdlib/ndarray/base/ctor' );
26+
var format = require( '@stdlib/string/format' );
2627

2728

2829
// MAIN //
@@ -54,7 +55,7 @@ function scalar2ndarray( value, dtype ) {
5455

5556
buf = buffer( dtype, 1 );
5657
if ( buf === null ) {
57-
throw new TypeError( 'invalid argument. Second argument must be a recognized data type. Value: `' + dtype + '`.' );
58+
throw new TypeError( format( 'invalid argument. Second argument must be a recognized data type. Value: `%s`.', dtype ) );
5859
}
5960
if ( /^complex/.test( dtype ) && typeof value === 'number' ) {
6061
value = [ value, 0.0 ]; // note: we're assuming that the ComplexXXArray setter accepts an array of interleaved real and imaginary components

lib/node_modules/@stdlib/ndarray/zeros-like/lib/main.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ var strides2offset = require( '@stdlib/ndarray/base/strides2offset' );
2929
var buffer = require( '@stdlib/ndarray/base/buffer' );
3030
var numel = require( '@stdlib/ndarray/base/numel' );
3131
var ndarray = require( '@stdlib/ndarray/ctor' );
32+
var format = require( '@stdlib/string/format' );
3233

3334

3435
// MAIN //
@@ -72,13 +73,13 @@ function zerosLike( x ) {
7273
var st;
7374

7475
if ( !isndarrayLike( x ) ) {
75-
throw new TypeError( 'invalid argument. First argument must be an ndarray-like object. Value: `' + x + '`.' );
76+
throw new TypeError( format( 'invalid argument. First argument must be an ndarray-like object. Value: `%s`.', x ) );
7677
}
7778
opts = {};
7879
if ( arguments.length > 1 ) {
7980
options = arguments[ 1 ];
8081
if ( !isPlainObject( options ) ) {
81-
throw new TypeError( 'invalid argument. Options argument must be an object. Value: `' + options + '`.' );
82+
throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );
8283
}
8384
if ( hasOwnProp( options, 'dtype' ) ) {
8485
opts.dtype = options.dtype;
@@ -91,7 +92,7 @@ function zerosLike( x ) {
9192
opts.shape = [ opts.shape ];
9293
}
9394
if ( !isNonNegativeIntegerArray( opts.shape ) ) {
94-
throw new TypeError( 'invalid option. `shape` option must either be a nonnegative integer or an array of nonnegative integers. Option: `' + opts.shape + '`.' );
95+
throw new TypeError( format( 'invalid option. `%s` option must either be a nonnegative integer or an array of nonnegative integers. Option: `%s`.', 'shape', opts.shape ) );
9596
}
9697
} else {
9798
opts.shape = x.shape;
@@ -120,7 +121,7 @@ function zerosLike( x ) {
120121
}
121122
buf = buffer( opts.dtype, len );
122123
if ( buf === null ) {
123-
throw new TypeError( 'invalid argument. First argument must have a recognized data type. Value: `' + opts.dtype + '`.' );
124+
throw new TypeError( format( 'invalid argument. First argument must have a recognized data type. Value: `%s`.', opts.dtype ) );
124125
}
125126
return new ndarray( opts.dtype, buf, opts.shape, st, strides2offset( opts.shape, st ), opts.order ); // eslint-disable-line max-len
126127
}

0 commit comments

Comments
 (0)