Skip to content

Commit 2ea2b71

Browse files
committed
Format error messages
1 parent 446aa70 commit 2ea2b71

File tree

22 files changed

+65
-46
lines changed

22 files changed

+65
-46
lines changed

lib/node_modules/@stdlib/_tools/remark/plugins/remark-img-equations-src-urls/lib/transformer.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ var logger = require( 'debug' );
2727
var visit = require( 'unist-util-visit' );
2828
var PATH_SEP = require( '@stdlib/constants/path/sep' );
2929
var trim = require( '@stdlib/string/trim' );
30+
var format = require( '@stdlib/string/format' );
3031
var jsdelivr = require( '@stdlib/_tools/utils/jsdelivr-url' );
3132
var git = require( './git.js' );
3233

@@ -86,7 +87,7 @@ function factory( opts ) {
8687
label = LABEL.exec( node.value );
8788
if ( label === null ) {
8889
debug( 'Invalid node: %s', node.value );
89-
throw new Error( 'invalid node. Equation element must have a valid label. Node: '+node.value+'.' );
90+
throw new Error( format( 'invalid node. Equation element must have a valid label. Node: `%s`.', node.value ) );
9091
}
9192
label = label[ 1 ];
9293
debug( 'Equation label: %s', label );

lib/node_modules/@stdlib/_tools/remark/plugins/remark-img-equations/lib/insert_equations.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
var logger = require( 'debug' );
2424
var createElement = require( '@stdlib/_tools/markdown/img-svg-equation' );
25+
var format = require( '@stdlib/string/format' );
2526

2627

2728
// VARIABLES //
@@ -62,23 +63,23 @@ function insertEquations( node, index, parent ) {
6263
label = LABEL.exec( node.value );
6364
if ( label === null ) {
6465
debug( 'Invalid node: %s', node.value );
65-
throw new Error( 'invalid node. Equation comments must have a valid label. Node: '+node.value+'.' );
66+
throw new Error( format( 'invalid node. Equation comments must have a valid label. Node: `%s`.', node.value ) );
6667
}
6768
label = label[ 1 ];
6869
debug( 'Label: %s', label );
6970

7071
alt = ALT.exec( node.value );
7172
if ( alt === null ) {
7273
debug( 'Invalid node: %s', node.value );
73-
throw new Error( 'invalid node. Equation comments must have valid alternate text. Node: '+node.value+'.' );
74+
throw new Error( format( 'invalid node. Equation comments must have valid alternate text. Node: `%s`.', node.value ) );
7475
}
7576
alt = alt[ 1 ];
7677
debug( 'Alternate text: %s', alt );
7778

7879
raw = RAW.exec( node.value );
7980
if ( raw === null ) {
8081
debug( 'Invalid node: %s', node.value );
81-
throw new Error( 'invalid node. Equation comments must have valid raw equation text. Node: '+node.value+'.' );
82+
throw new Error( format( 'invalid node. Equation comments must have valid raw equation text. Node: `%s`.', node.value ) );
8283
}
8384
raw = raw[ 1 ];
8485
debug( 'Raw equation: %s', raw );
@@ -108,7 +109,7 @@ function insertEquations( node, index, parent ) {
108109
}
109110
else {
110111
debug( 'Invalid node: %s', node.value );
111-
throw new Error( 'invalid node. Invalid equation comment. Ensure that the Markdown file includes both starting and ending equation comments. Node: `' + node.value + '`.' );
112+
throw new Error( format( 'invalid node. Invalid equation comment. Ensure that the Markdown file includes both starting and ending equation comments. Node: `%s`.', node.value ) );
112113
}
113114
}
114115
}

lib/node_modules/@stdlib/_tools/remark/plugins/remark-run-javascript-examples/lib/parse_config.js

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

2323
var trim = require( '@stdlib/string/trim' );
24+
var format = require( '@stdlib/string/format' );
2425
var parseJSON = require( '@stdlib/utils/parse-json' );
2526

2627

@@ -73,7 +74,7 @@ function parse( str ) {
7374

7475
// Validate that a key-value pair has been provided:
7576
if ( conf[ i ].length !== 2 ) {
76-
return new Error( 'invalid configuration. Code block configuration settings should be provided as comma-separated `key:value` pairs; e.g., `foo:true, bar:"string", baz:["error",2]`. Value: `' + conf[ i ].join( ':' ) + '`.' );
77+
return new Error( format( 'invalid configuration. Code block configuration settings should be provided as comma-separated `key:value` pairs; e.g., `foo:true, bar:"string", baz:["error",2]`. Value: `%s`.', conf[ i ].join( ':' ) ) );
7778
}
7879
// Trim any excess leading or trailing whitespace from the key and value:
7980
key = trim( conf[ i ][ 0 ] );
@@ -82,7 +83,7 @@ function parse( str ) {
8283
// Attempt to parse the value as JSON:
8384
v = parseJSON( v );
8485
if ( v instanceof Error ) {
85-
return new Error( 'invalid configuration. Code block configuration values should be parseable as JSON. Value: `' + trim( conf[i][1] ) + '`.' );
86+
return new Error( format( 'invalid configuration. Code block configuration values should be parseable as JSON. Value: `%s`.', trim( conf[i][1] ) ) );
8687
}
8788
// Update output object:
8889
out[ key ] = v;

lib/node_modules/@stdlib/_tools/remark/plugins/remark-run-javascript-examples/lib/runner.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ var join = require( 'path' ).join;
2525
var logger = require( 'debug' );
2626
var replace = require( '@stdlib/string/replace' );
2727
var now = require( '@stdlib/time/now' );
28+
var format = require( '@stdlib/string/format' );
2829
var dirname = require( '@stdlib/utils/dirname' );
2930
var EXEC_PATH = require( '@stdlib/process/exec-path' );
3031
var parseConfig = require( './parse_config.js' );
@@ -264,12 +265,12 @@ function factory( options ) {
264265
// Ensure that we don't return an error when the code block intentionally threw an exception...
265266
if ( !conf.throws ) {
266267
// TODO: the generated error is a bit messy. Cleaning-up may require manual modification of the stacktrace(s), etc.
267-
error = new Error( 'unexpected error. Encountered an error when executing code block. File: ' + (file.path || '(undefined)') + '. Message: ' + error.message );
268+
error = new Error( format( 'unexpected error. Encountered an error when executing code block. File: %s. Message: %s', file.path || '(undefined)', error.message ) );
268269
return done( error );
269270
}
270271
} else if ( conf.throws ) {
271272
debug( 'Code block failed to throw an exception.' );
272-
error = new Error( 'unexpected error. Expected code block to throw an exception. File: ' + (file.path || '(undefined)') + '.' );
273+
error = new Error( format( 'unexpected error. Expected code block to throw an exception. File: %s.', file.path || '(undefined)' ) );
273274
return done( error );
274275
}
275276
if ( !options.quiet && !options.silent ) {

lib/node_modules/@stdlib/_tools/remark/plugins/remark-stdlib-related/lib/transformer.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ var visit = require( 'unist-util-visit' );
2626
var rootDir = require( '@stdlib/_tools/utils/root-dir' );
2727
var pkg2related = require( '@stdlib/namespace/pkg2related' );
2828
var uncapitalizeDescription = require( '@stdlib/_tools/utils/uncapitalize-pkg-description' );
29+
var format = require( '@stdlib/string/format' );
2930
var readJSON = require( '@stdlib/fs/read-json' ).sync;
3031

3132

@@ -154,7 +155,7 @@ function transformer( tree, file ) {
154155
}
155156
}
156157
if ( i === parent.children.length - 1 ) {
157-
throw new Error( 'invalid node. Ensure that the Markdown file includes both a starting `<section class="related">` and closing `</section>\n\n<!-- /.related -->`. Node: `' + node.value + '`.' );
158+
throw new Error( format( 'invalid node. Ensure that the Markdown file includes both a starting `<section class="related">` and closing `</section>\n\n<!-- /.related -->`. Node: `%s`.', node.value ) );
158159
}
159160
if ( found ) {
160161
debug( 'Append links to links section...' );

lib/node_modules/@stdlib/_tools/remark/plugins/remark-svg-equations-to-file/lib/transformer.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ var mkdirp = require( 'mkdirp' );
2727
var visit = require( 'unist-util-visit' );
2828
var writeFile = require( '@stdlib/fs/write-file' );
2929
var tex2svg = require( '@stdlib/_tools/utils/tex-equation-to-svg' );
30+
var format = require( '@stdlib/string/format' );
3031

3132

3233
// VARIABLES //
@@ -128,7 +129,7 @@ function factory( opts ) {
128129
raw = RAW.exec( nodes[ idx ].value );
129130
if ( raw === null ) {
130131
debug( 'Invalid node: %s', nodes[ idx ].value );
131-
err = new Error( 'invalid node. Equation comments must have valid raw equation text. Node: '+nodes[ idx ].value+'.' );
132+
err = new Error( format( 'invalid node. Equation comments must have valid raw equation text. Node: `%s`.', nodes[ idx ].value ) );
132133
return done( err );
133134
}
134135
raw = raw[ 1 ];
@@ -157,7 +158,7 @@ function factory( opts ) {
157158
label = LABEL.exec( nodes[ idx ].value );
158159
if ( label === null ) {
159160
debug( 'Invalid node: %s', nodes[ idx ].value );
160-
error = new Error( 'invalid node. Equation comments must have valid labels. Node: '+nodes[ idx ].value+'.' );
161+
error = new Error( format( 'invalid node. Equation comments must have valid labels. Node: `%s`.', nodes[ idx ].value ) );
161162
return done( error );
162163
}
163164
label = label[ 1 ];

lib/node_modules/@stdlib/_tools/remark/plugins/remark-svg-equations/lib/transformer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ function transformer( tree, file, clbk ) {
161161
}
162162
else {
163163
debug( 'Invalid node: %s', parent.children[ idx ].value );
164-
error = new Error( 'invalid node. Invalid equation comment. Ensure that the Markdown file includes both starting and ending equation comments. Node: `' + parent.children[ idx ].value + '`.' );
164+
error = new Error( format( 'invalid node. Invalid equation comment. Ensure that the Markdown file includes both starting and ending equation comments. Node: `%s`.', parent.children[ idx ].value ) );
165165
return done( error );
166166
}
167167
debug( 'Finished processing Markdown equation.' );

lib/node_modules/@stdlib/array/datespace/lib/main.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,15 @@ function validDate( value, name ) {
6161
}
6262
if ( type === 'number' ) {
6363
if ( !timestamp.test( value ) ) {
64-
throw new Error( 'invalid argument. Numeric ' + name.toLowerCase() + ' date must be either a Unix or Javascript timestamp.' );
64+
throw new Error( format( 'invalid argument. Numeric %s date must be either a Unix or Javascript timestamp.', name.toLowerCase() ) );
6565
}
6666
if ( value.toString().length === 10 ) {
6767
value *= 1000; // sec to ms
6868
}
6969
value = new Date( value );
7070
}
7171
if ( !(value instanceof Date) ) {
72-
throw new TypeError( 'invalid argument. ' + name + ' date must either be a date string, Date object, Unix timestamp, or JavaScript timestamp.' );
72+
throw new TypeError( format( 'invalid argument. %s date must either be a date string, Date object, Unix timestamp, or JavaScript timestamp.', name ) );
7373
}
7474
return value;
7575
}

lib/node_modules/@stdlib/ml/incr/binary-classification/lib/main.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ function incrBinaryClassification( N, options ) {
143143
throw new TypeError( format( 'invalid argument. Second argument must be either +1 or -1. Value: `%s`.', y ) );
144144
}
145145
if ( x.shape[ 0 ] !== model.nfeatures ) {
146-
throw new TypeError( 'invalid argument. First argument must be a one-dimensional ndarray of length ' + model.nfeatures + '. Actual length: `' + x.shape[ 0 ] + '`.' );
146+
throw new TypeError( format( 'invalid argument. First argument must be a one-dimensional ndarray of length `%u`. Actual length: `%u`.', model.nfeatures, x.shape[ 0 ] ) );
147147
}
148148
model.update( x, y );
149149
return model.coefficients;
@@ -185,13 +185,13 @@ function incrBinaryClassification( N, options ) {
185185
}
186186
sh = X.shape;
187187
if ( sh[ sh.length-1 ] !== N ) {
188-
throw new TypeError( 'invalid argument. First argument must be an ndarray whose last dimension is of size ' + N + '. Actual size: `' + sh[ sh.length-1 ] + '`.' );
188+
throw new TypeError( format( 'invalid argument. First argument must be an ndarray whose last dimension is of size `%u`. Actual size: `%u`.', N, sh[ sh.length-1 ] ) );
189189
}
190190
t = 'label';
191191
if ( arguments.length > 1 ) {
192192
if ( type === 'probability' ) {
193193
if ( opts.loss !== 'log' && opts.loss !== 'modifiedHuber' ) {
194-
throw new Error( 'invalid argument. Second argument is incompatible with model loss function. Probability predictions are only supported when the loss function is either `log` or `modifiedHuber`. Model loss function: `' + opts.loss + '`.' );
194+
throw new Error( format( 'invalid argument. Second argument is incompatible with model loss function. Probability predictions are only supported when the loss function is either `log` or `modifiedHuber`. Model loss function: `%s`.', opts.loss ) );
195195
}
196196
} else if ( type !== 'label' && type !== 'linear' ) {
197197
throw new TypeError( format( 'invalid argument. Second argument must be a string value equal to either \'label\', \'probability\', or \'linear\'. Value: `%s`.', type ) );

lib/node_modules/@stdlib/ml/incr/binary-classification/lib/validate.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,29 +79,29 @@ function validate( opts, options ) {
7979
name = options.learningRate[ 0 ];
8080
opts.learningRate[ 0 ] = name;
8181
if ( !contains( LEARNING_RATES, name ) ) {
82-
return new TypeError( 'invalid option. First `learningRate` option must be one of the following values: \'' + LEARNING_RATES.join( '\', \'' ) + '\'. Option: `' + name + '`.' );
82+
return new TypeError( format( 'invalid option. First `%s` option must be one of the following: \'%s\'. Option: `%s`.', 'learningRate', LEARNING_RATES.join( '\', \'' ), name ) );
8383
}
8484
if ( options.learningRate.length > 1 ) {
8585
if ( name === 'constant' || name === 'invscaling' ) {
8686
opts.learningRate[ 1 ] = options.learningRate[ 1 ];
8787
if ( !isPositiveNumber( opts.learningRate[ 1 ] ) ) {
88-
return new TypeError( 'invalid option. Second `learningRate` option must be a positive number. Option: `' + opts.learningRate[ 1 ] + '`.' );
88+
return new TypeError( format( 'invalid option. Second `%s` option must be a positive number. Option: `%f`.', 'learningRate', opts.learningRate[ 1 ] ) );
8989
}
9090
}
9191
}
9292
if ( options.learningRate.length > 2 ) {
9393
if ( name === 'invscaling' ) {
9494
opts.learningRate[ 2 ] = options.learningRate[ 2 ];
9595
if ( !isNumber( opts.learningRate[ 2 ] ) ) {
96-
return new TypeError( 'invalid option. Third `learningRate` option must be a number. Option: `' + opts.learningRate[ 2 ] + '`.' );
96+
return new TypeError( format( 'invalid option. Third `%s` option must be a number. Option: `%f`.', 'learningRate', opts.learningRate[ 2 ] ) );
9797
}
9898
}
9999
}
100100
}
101101
if ( hasOwnProp( options, 'loss' ) ) {
102102
opts.loss = options.loss;
103103
if ( !contains( LOSS_FUNCTIONS, opts.loss ) ) {
104-
return new TypeError( 'invalid option. `loss` option must be one of the following values: \'' + LOSS_FUNCTIONS.join( '\', \'' ) + '\'. Option: `' + opts.loss + '`.' );
104+
return new TypeError( format( 'invalid option. `%s` option must be one of the following: \'%s\'. Option: `%s`.', 'loss', LOSS_FUNCTIONS.join( '\', \'' ), opts.loss ) );
105105
}
106106
}
107107
return null;

0 commit comments

Comments
 (0)