Skip to content

Commit f58749a

Browse files
committed
Format error messages
1 parent a62611d commit f58749a

File tree

42 files changed

+197
-155
lines changed

Some content is hidden

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

42 files changed

+197
-155
lines changed

lib/node_modules/@stdlib/array/linspace/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 isString = require( '@stdlib/assert/is-string' ).isPrimitive;
2626
var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive;
27+
var format = require( '@stdlib/string/format' );
2728

2829

2930
// MAIN //
@@ -50,18 +51,18 @@ var isBoolean = require( '@stdlib/assert/is-boolean' ).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+
return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );
5455
}
5556
if ( hasOwnProp( options, 'dtype' ) ) {
5657
opts.dtype = options.dtype;
5758
if ( !isString( opts.dtype ) ) {
58-
return new TypeError( 'invalid option. `dtype` option must be a string. Option: `' + opts.dtype + '`.' );
59+
return new TypeError( format( 'invalid option. `%s` option must be a string primitive. Option: `%s`.', 'dtype', opts.dtype ) );
5960
}
6061
}
6162
if ( hasOwnProp( options, 'endpoint' ) ) {
6263
opts.endpoint = options.endpoint;
6364
if ( !isBoolean( opts.endpoint ) ) {
64-
return new TypeError( 'invalid option. `endpoint` option must be a boolean. Option: `' + opts.endpoint + '`.' );
65+
return new TypeError( format( 'invalid option. `%s` option must be a boolean primitive. Option: `%s`.', 'endpoint', opts.endpoint ) );
6566
}
6667
}
6768
return null;

lib/node_modules/@stdlib/array/pool/lib/validate.js

Lines changed: 3 additions & 2 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 isNonNegativeInteger = require( '@stdlib/assert/is-nonnegative-integer' ).isPrimitive;
26+
var format = require( '@stdlib/string/format' );
2627

2728

2829
// MAIN //
@@ -48,12 +49,12 @@ var isNonNegativeInteger = require( '@stdlib/assert/is-nonnegative-integer' ).is
4849
*/
4950
function validate( opts, options ) {
5051
if ( !isObject( options ) ) {
51-
return new TypeError( 'invalid argument. Options must be an object. Value: `' + options + '`.' );
52+
return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );
5253
}
5354
if ( hasOwnProp( options, 'highWaterMark' ) ) {
5455
opts.highWaterMark = options.highWaterMark;
5556
if ( !isNonNegativeInteger( opts.highWaterMark ) ) {
56-
return new TypeError( 'invalid option. `highWaterMark` option must be a nonnegative integer. Option: `' + opts.highWaterMark + '`.' );
57+
return new TypeError( format( 'invalid option. `%s` option must be a nonnegative integer. Option: `%s`.', 'highWaterMark', opts.highWaterMark ) );
5758
}
5859
}
5960
return null;

lib/node_modules/@stdlib/streams/node/debug-sink/lib/validate.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ var hasOwnProp = require( '@stdlib/assert/has-own-property' );
2525
var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive;
2626
var isNonNegative = require( '@stdlib/assert/is-nonnegative-number' ).isPrimitive;
2727
var isString = require( '@stdlib/assert/is-string' ).isPrimitive;
28+
var format = require( '@stdlib/string/format' );
2829

2930

3031
// MAIN //
@@ -55,36 +56,36 @@ var isString = require( '@stdlib/assert/is-string' ).isPrimitive;
5556
*/
5657
function validate( opts, options ) {
5758
if ( !isObject( options ) ) {
58-
return new TypeError( 'invalid argument. Options argument must be an object. Value: `' + options + '`.' );
59+
return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );
5960
}
6061
if ( hasOwnProp( options, 'name' ) ) {
6162
opts.name = options.name;
6263
if ( !isString( opts.name ) ) {
63-
return new TypeError( 'invalid option. `name` option must be a primitive string. Option: `' + opts.name + '`.' );
64+
return new TypeError( format( 'invalid option. `%s` option must be a string primitive. Option: `%s`.', 'name', opts.name ) );
6465
}
6566
}
6667
if ( hasOwnProp( options, 'objectMode' ) ) {
6768
opts.objectMode = options.objectMode;
6869
if ( !isBoolean( opts.objectMode ) ) {
69-
return new TypeError( 'invalid option. `objectMode` option must be a primitive boolean. Option: `' + opts.objectMode + '`.' );
70+
return new TypeError( format( 'invalid option. `%s` option must be a primitive boolean. Option: `%s`.', 'objectMode', opts.objectMode ) );
7071
}
7172
}
7273
if ( hasOwnProp( options, 'highWaterMark' ) ) {
7374
opts.highWaterMark = options.highWaterMark;
7475
if ( !isNonNegative( opts.highWaterMark ) ) {
75-
return new TypeError( 'invalid option. `highWaterMark` option must be a nonnegative number. Option: `' + opts.highWaterMark + '`.' );
76+
return new TypeError( format( 'invalid option. `%s` option must be a nonnegative number. Option: `%s`.', 'highWaterMark', opts.highWaterMark ) );
7677
}
7778
}
7879
if ( hasOwnProp( options, 'decodeStrings' ) ) {
7980
opts.decodeStrings = options.decodeStrings;
8081
if ( !isBoolean( opts.decodeStrings ) ) {
81-
return new TypeError( 'invalid option. `decodeStrings` option must be a primitive boolean. Option: `' + opts.decodeStrings + '`.' );
82+
return new TypeError( format( 'invalid option. `%s` option must be a boolean primitive. Option: `%s`.', 'decodeStrings', opts.decodeStrings ) );
8283
}
8384
}
8485
if ( hasOwnProp( options, 'defaultEncoding' ) ) {
8586
opts.defaultEncoding = options.defaultEncoding;
8687
if ( !isString( opts.defaultEncoding ) ) {
87-
return new TypeError( 'invalid option. `defaultEncoding` option must be a primitive string. Option: `' + opts.defaultEncoding + '`.' );
88+
return new TypeError( format( 'invalid option. `%s` option must be a string primitive. Option: `%s`.', 'defaultEncoding', opts.defaultEncoding ) );
8889
}
8990
}
9091
return null;

lib/node_modules/@stdlib/streams/node/debug/lib/validate.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ var hasOwnProp = require( '@stdlib/assert/has-own-property' );
2525
var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive;
2626
var isNonNegative = require( '@stdlib/assert/is-nonnegative-number' ).isPrimitive;
2727
var isString = require( '@stdlib/assert/is-string' ).isPrimitive;
28+
var format = require( '@stdlib/string/format' );
2829

2930

3031
// MAIN //
@@ -44,36 +45,36 @@ var isString = require( '@stdlib/assert/is-string' ).isPrimitive;
4445
*/
4546
function validate( opts, options ) {
4647
if ( !isObject( options ) ) {
47-
return new TypeError( 'invalid argument. Options argument must be an object. Value: `' + options + '`.' );
48+
return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );
4849
}
4950
if ( hasOwnProp( options, 'name' ) ) {
5051
opts.name = options.name;
5152
if ( !isString( opts.name ) ) {
52-
return new TypeError( 'invalid option. `name` option must be a primitive string. Option: `' + opts.name + '`.' );
53+
return new TypeError( format( 'invalid option. `%s` option must be a primitive string. Option: `%s`.', 'name', opts.name ) );
5354
}
5455
}
5556
if ( hasOwnProp( options, 'objectMode' ) ) {
5657
opts.objectMode = options.objectMode;
5758
if ( !isBoolean( opts.objectMode ) ) {
58-
return new TypeError( 'invalid option. `objectMode` option must be a primitive boolean. Option: `' + opts.objectMode + '`.' );
59+
return new TypeError( format( 'invalid option. `%s` option must be a primitive boolean. Option: `%s`.', 'objectMode', opts.objectMode ) );
5960
}
6061
}
6162
if ( hasOwnProp( options, 'readableObjectMode' ) ) {
6263
opts.readableObjectMode = options.readableObjectMode;
6364
if ( !isBoolean( opts.readableObjectMode ) ) {
64-
return new TypeError( 'invalid option. `readableObjectMode` option must be a primitive boolean. Option: `' + opts.readableObjectMode + '`.' );
65+
return new TypeError( format( 'invalid option. `%s` option must be a primitive boolean. Option: `%s`.', 'readableObjectMode', opts.readableObjectMode ) );
6566
}
6667
}
6768
if ( hasOwnProp( options, 'allowHalfOpen' ) ) {
6869
opts.allowHalfOpen = options.allowHalfOpen;
6970
if ( !isBoolean( opts.allowHalfOpen ) ) {
70-
return new TypeError( 'invalid option. `allowHalfOpen` option must be a primitive boolean. Option: `' + opts.allowHalfOpen + '`.' );
71+
return new TypeError( format( 'invalid option. `%s` option must be a primitive boolean. Option: `%s`.', 'allowHalfOpen', opts.allowHalfOpen ) );
7172
}
7273
}
7374
if ( hasOwnProp( options, 'highWaterMark' ) ) {
7475
opts.highWaterMark = options.highWaterMark;
7576
if ( !isNonNegative( opts.highWaterMark ) ) {
76-
return new TypeError( 'invalid option. `highWaterMark` option must be a nonnegative number. Option: `' + opts.highWaterMark + '`.' );
77+
return new TypeError( format( 'invalid option. `%s` option must be a nonnegative number. Option: `%s`.', 'highWaterMark', opts.highWaterMark ) );
7778
}
7879
}
7980
return null;

lib/node_modules/@stdlib/streams/node/empty/lib/validate.js

Lines changed: 3 additions & 2 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 isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive;
26+
var format = require( '@stdlib/string/format' );
2627

2728

2829
// MAIN //
@@ -48,12 +49,12 @@ var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive;
4849
*/
4950
function validate( opts, options ) {
5051
if ( !isObject( options ) ) {
51-
return new TypeError( 'invalid argument. Options must be an object. Value: `' + options + '`.' );
52+
return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );
5253
}
5354
if ( hasOwnProp( options, 'objectMode' ) ) {
5455
opts.objectMode = options.objectMode;
5556
if ( !isBoolean( opts.objectMode ) ) {
56-
return new TypeError( 'invalid option. `objectMode` option must be a primitive boolean. Option: `' + opts.objectMode + '`.' );
57+
return new TypeError( format( 'invalid option. `%s` option must be a boolean primitive. Option: `%s`.', 'objectMode', opts.objectMode ) );
5758
}
5859
}
5960
return null;

lib/node_modules/@stdlib/streams/node/from-array/lib/validate.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive;
2626
var isNonNegative = require( '@stdlib/assert/is-nonnegative-number' ).isPrimitive;
2727
var isString = require( '@stdlib/assert/is-string' ).isPrimitive;
2828
var isFunction = require( '@stdlib/assert/is-function' );
29+
var format = require( '@stdlib/string/format' );
2930

3031

3132
// MAIN //
@@ -56,42 +57,42 @@ var isFunction = require( '@stdlib/assert/is-function' );
5657
*/
5758
function validate( opts, options ) {
5859
if ( !isObject( options ) ) {
59-
return new TypeError( 'invalid argument. Options must be an object. Value: `' + options + '`.' );
60+
return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );
6061
}
6162
if ( hasOwnProp( options, 'sep' ) ) {
6263
opts.sep = options.sep;
6364
if ( !isString( opts.sep ) ) {
64-
return new TypeError( 'invalid option. `sep` option must be a primitive string. Option: `' + opts.sep + '`.' );
65+
return new TypeError( format( 'invalid option. `%s` option must be a string primitive. Option: `%s`.', 'sep', opts.sep ) );
6566
}
6667
}
6768
if ( hasOwnProp( options, 'objectMode' ) ) {
6869
opts.objectMode = options.objectMode;
6970
if ( !isBoolean( opts.objectMode ) ) {
70-
return new TypeError( 'invalid option. `objectMode` option must be a primitive boolean. Option: `' + opts.objectMode + '`.' );
71+
return new TypeError( format( 'invalid option. `%s` option must be a primitive boolean. Option: `%s`.', 'objectMode', opts.objectMode ) );
7172
}
7273
}
7374
if ( hasOwnProp( options, 'encoding' ) ) {
7475
opts.encoding = options.encoding;
7576
if ( !isString( opts.encoding ) && opts.encoding !== null ) {
76-
return new TypeError( 'invalid option. `encoding` option must be a primitive string or null. Option: `' + opts.encoding + '`.' );
77+
return new TypeError( format( 'invalid option. `%s` option must be a string primitive or null. Option: `%s`.', 'encoding', opts.encoding ) );
7778
}
7879
}
7980
if ( hasOwnProp( options, 'highWaterMark' ) ) {
8081
opts.highWaterMark = options.highWaterMark;
8182
if ( !isNonNegative( opts.highWaterMark ) ) {
82-
return new TypeError( 'invalid option. `highWaterMark` option must be a nonnegative number. Option: `' + opts.highWaterMark + '`.' );
83+
return new TypeError( format( 'invalid option. `%s` option must be a nonnegative number. Option: `%s`.', 'highWaterMark', opts.highWaterMark ) );
8384
}
8485
}
8586
if ( hasOwnProp( options, 'serialize' ) ) {
8687
opts.serialize = options.serialize;
8788
if ( !isFunction( opts.serialize ) ) {
88-
return new TypeError( 'invalid option. `serialize` option must be a function. Option: `' + opts.serialize + '`.' );
89+
return new TypeError( format( 'invalid option. `%s` option must be a function. Option: `%s`.', 'serialize', opts.serialize ) );
8990
}
9091
}
9192
if ( hasOwnProp( options, 'dir' ) ) {
9293
opts.dir = options.dir;
9394
if ( opts.dir !== 1 && opts.dir !== -1 ) {
94-
return new TypeError( 'invalid option. `dir` option must be either `1` or `-1`. Option: `' + opts.dir + '`.' );
95+
return new TypeError( format( 'invalid option. `%s` option must be either `1` or `-1`. Option: `%s`.', 'dir', opts.dir ) );
9596
}
9697
}
9798
return null;

lib/node_modules/@stdlib/streams/node/from-circular-array/lib/validate.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ var isNonNegative = require( '@stdlib/assert/is-nonnegative-number' ).isPrimitiv
2727
var isNonNegativeInteger = require( '@stdlib/assert/is-nonnegative-integer' ).isPrimitive;
2828
var isString = require( '@stdlib/assert/is-string' ).isPrimitive;
2929
var isFunction = require( '@stdlib/assert/is-function' );
30+
var format = require( '@stdlib/string/format' );
3031

3132

3233
// MAIN //
@@ -58,48 +59,48 @@ var isFunction = require( '@stdlib/assert/is-function' );
5859
*/
5960
function validate( opts, options ) {
6061
if ( !isObject( options ) ) {
61-
return new TypeError( 'invalid argument. Options must be an object. Value: `' + options + '`.' );
62+
return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );
6263
}
6364
if ( hasOwnProp( options, 'sep' ) ) {
6465
opts.sep = options.sep;
6566
if ( !isString( opts.sep ) ) {
66-
return new TypeError( 'invalid option. `sep` option must be a primitive string. Option: `' + opts.sep + '`.' );
67+
return new TypeError( format( 'invalid option. `%s` option must be a string primitive. Option: `%s`.', 'sep', opts.sep ) );
6768
}
6869
}
6970
if ( hasOwnProp( options, 'objectMode' ) ) {
7071
opts.objectMode = options.objectMode;
7172
if ( !isBoolean( opts.objectMode ) ) {
72-
return new TypeError( 'invalid option. `objectMode` option must be a primitive boolean. Option: `' + opts.objectMode + '`.' );
73+
return new TypeError( format( 'invalid option. `%s` option must be a primitive boolean. Option: `%s`.', 'objectMode', opts.objectMode ) );
7374
}
7475
}
7576
if ( hasOwnProp( options, 'encoding' ) ) {
7677
opts.encoding = options.encoding;
7778
if ( !isString( opts.encoding ) && opts.encoding !== null ) {
78-
return new TypeError( 'invalid option. `encoding` option must be a primitive string or null. Option: `' + opts.encoding + '`.' );
79+
return new TypeError( format( 'invalid option. `%s` option must be a string primitive or null. Option: `%s`.', 'encoding', opts.encoding ) );
7980
}
8081
}
8182
if ( hasOwnProp( options, 'highWaterMark' ) ) {
8283
opts.highWaterMark = options.highWaterMark;
8384
if ( !isNonNegative( opts.highWaterMark ) ) {
84-
return new TypeError( 'invalid option. `highWaterMark` option must be a nonnegative number. Option: `' + opts.highWaterMark + '`.' );
85+
return new TypeError( format( 'invalid option. `%s` option must be a nonnegative number. Option: `%s`.', 'highWaterMark', opts.highWaterMark ) );
8586
}
8687
}
8788
if ( hasOwnProp( options, 'serialize' ) ) {
8889
opts.serialize = options.serialize;
8990
if ( !isFunction( opts.serialize ) ) {
90-
return new TypeError( 'invalid option. `serialize` option must be a function. Option: `' + opts.serialize + '`.' );
91+
return new TypeError( format( 'invalid option. `%s` option must be a function. Option: `%s`.', 'serialize', opts.serialize ) );
9192
}
9293
}
9394
if ( hasOwnProp( options, 'iter' ) ) {
9495
opts.iter = options.iter;
9596
if ( !isNonNegativeInteger( opts.iter ) ) {
96-
return new TypeError( 'invalid option. `iter` option must be a nonnegative integer. Option: `' + opts.iter + '`.' );
97+
return new TypeError( format( 'invalid option. `%s` option must be a nonnegative integer. Option: `%s`.', 'iter', opts.iter ) );
9798
}
9899
}
99100
if ( hasOwnProp( options, 'dir' ) ) {
100101
opts.dir = options.dir;
101102
if ( opts.dir !== 1 && opts.dir !== -1 ) {
102-
return new TypeError( 'invalid option. `dir` option must be either `1` or `-1`. Option: `' + opts.dir + '`.' );
103+
return new TypeError( format( 'invalid option. `%s` option must be either `1` or `-1`. Option: `%s`.', 'dir', opts.dir ) );
103104
}
104105
}
105106
return null;

lib/node_modules/@stdlib/streams/node/from-constant/lib/validate.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive;
2626
var isNonNegative = require( '@stdlib/assert/is-nonnegative-number' ).isPrimitive;
2727
var isString = require( '@stdlib/assert/is-string' ).isPrimitive;
2828
var isNonNegativeInteger = require( '@stdlib/assert/is-nonnegative-integer' ).isPrimitive;
29+
var format = require( '@stdlib/string/format' );
2930

3031

3132
// MAIN //
@@ -55,36 +56,36 @@ var isNonNegativeInteger = require( '@stdlib/assert/is-nonnegative-integer' ).is
5556
*/
5657
function validate( opts, options ) {
5758
if ( !isObject( options ) ) {
58-
return new TypeError( 'invalid argument. Options must be an object. Value: `' + options + '`.' );
59+
return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );
5960
}
6061
if ( hasOwnProp( options, 'sep' ) ) {
6162
opts.sep = options.sep;
6263
if ( !isString( opts.sep ) ) {
63-
return new TypeError( 'invalid option. `sep` option must be a primitive string. Option: `' + opts.sep + '`.' );
64+
return new TypeError( format( 'invalid option. `%s` option must be a string primitive. Option: `%s`.', 'sep', opts.sep ) );
6465
}
6566
}
6667
if ( hasOwnProp( options, 'objectMode' ) ) {
6768
opts.objectMode = options.objectMode;
6869
if ( !isBoolean( opts.objectMode ) ) {
69-
return new TypeError( 'invalid option. `objectMode` option must be a primitive boolean. Option: `' + opts.objectMode + '`.' );
70+
return new TypeError( format( 'invalid option. `%s` option must be a primitive boolean. Option: `%s`.', 'objectMode', opts.objectMode ) );
7071
}
7172
}
7273
if ( hasOwnProp( options, 'encoding' ) ) {
7374
opts.encoding = options.encoding;
7475
if ( !isString( opts.encoding ) && opts.encoding !== null ) {
75-
return new TypeError( 'invalid option. `encoding` option must be a primitive string or null. Option: `' + opts.encoding + '`.' );
76+
return new TypeError( format( 'invalid option. `%s` option must be a string primitive or null. Option: `%s`.', 'encoding', opts.encoding ) );
7677
}
7778
}
7879
if ( hasOwnProp( options, 'highWaterMark' ) ) {
7980
opts.highWaterMark = options.highWaterMark;
8081
if ( !isNonNegative( opts.highWaterMark ) ) {
81-
return new TypeError( 'invalid option. `highWaterMark` option must be a nonnegative number. Option: `' + opts.highWaterMark + '`.' );
82+
return new TypeError( format( 'invalid option. `%s` option must be a nonnegative number. Option: `%s`.', 'highWaterMark', opts.highWaterMark ) );
8283
}
8384
}
8485
if ( hasOwnProp( options, 'iter' ) ) {
8586
opts.iter = options.iter;
8687
if ( !isNonNegativeInteger( opts.iter ) ) {
87-
return new TypeError( 'invalid option. `iter` option must be a nonnegative integer. Option: `' + opts.iter + '`.' );
88+
return new TypeError( format( 'invalid option. `%s` option must be a nonnegative integer. Option: `%s`.', 'iter', opts.iter ) );
8889
}
8990
}
9091
return null;

0 commit comments

Comments
 (0)