Skip to content

Commit 62daba0

Browse files
committed
Transform error messages
1 parent 1c2c038 commit 62daba0

File tree

2 files changed

+17
-17
lines changed

2 files changed

+17
-17
lines changed

lib/main.js

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ var createBuffer = require( '@stdlib/ndarray-base-buffer' );
3939
var getType = require( '@stdlib/ndarray-base-buffer-dtype' );
4040
var arrayShape = require( '@stdlib/array-shape' );
4141
var flatten = require( '@stdlib/array-base-flatten' );
42-
var format = require( '@stdlib/string-format' );
42+
var format = require( '@stdlib/error-tools-fmtprodmsg' );
4343
var isArrayLikeObject = require( './is_array_like_object.js' );
4444
var getDefaults = require( './defaults.js' );
4545
var castBuffer = require( './cast_buffer.js' );
@@ -134,23 +134,23 @@ function array() {
134134
} else {
135135
options = arguments[ 0 ];
136136
if ( !isObject( options ) ) {
137-
throw new TypeError( format( 'invalid argument. Must provide either a valid data source, options argument, or both. Value: `%s`.', options ) );
137+
throw new TypeError( format( '0Le5K', options ) );
138138
}
139139
if ( hasOwnProp( options, 'buffer' ) ) {
140140
buffer = options.buffer;
141141
if ( !isArrayLikeObject( buffer ) ) { // weak test
142-
throw new TypeError( format( 'invalid option. `%s` option must be an array-like object, typed-array-like, a Buffer, or an ndarray. Option: `%s`.', 'buffer', buffer ) );
142+
throw new TypeError( format( '0Le5L', 'buffer', buffer ) );
143143
}
144144
}
145145
}
146146
} else {
147147
buffer = arguments[ 0 ];
148148
if ( !isArrayLikeObject( buffer ) ) { // weak test
149-
throw new TypeError( format( 'invalid option. Data source must be an array-like object, typed-array-like, a Buffer, or an ndarray. Value: `%s`.', buffer ) );
149+
throw new TypeError( format( '0Le5M', buffer ) );
150150
}
151151
options = arguments[ 1 ];
152152
if ( !isObject( options ) ) {
153-
throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );
153+
throw new TypeError( format( '0Le2h', options ) );
154154
}
155155
// Note: we ignore whether `options` has a `buffer` property
156156
}
@@ -170,23 +170,23 @@ function array() {
170170
if ( hasOwnProp( options, 'casting' ) ) {
171171
opts.casting = options.casting;
172172
if ( !isCastingMode( opts.casting ) ) {
173-
throw new TypeError( format( 'invalid option. `%s` option must be a recognized casting mode. Option: `%s`.', 'casting', opts.casting ) );
173+
throw new TypeError( format( '0Le5N', 'casting', opts.casting ) );
174174
}
175175
} else {
176176
opts.casting = defaults.casting;
177177
}
178178
if ( hasOwnProp( options, 'flatten' ) ) {
179179
opts.flatten = options.flatten;
180180
if ( !isBoolean( opts.flatten ) ) {
181-
throw new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'flatten', opts.flatten ) );
181+
throw new TypeError( format( '0Le30', 'flatten', opts.flatten ) );
182182
}
183183
} else {
184184
opts.flatten = defaults.flatten;
185185
}
186186
if ( hasOwnProp( options, 'ndmin' ) ) {
187187
opts.ndmin = options.ndmin;
188188
if ( !isNonNegativeInteger( opts.ndmin ) ) {
189-
throw new TypeError( format( 'invalid option. `%s` option must be a nonnegative integer. Option: `%s`.', 'ndmin', opts.ndmin ) );
189+
throw new TypeError( format( '0Le35', 'ndmin', opts.ndmin ) );
190190
}
191191
// TODO: validate that minimum number of dimensions does not exceed the maximum number of possible dimensions (in theory, infinite; in practice, determined by max array length; see https://github.com/stdlib-js/stdlib/blob/ac350059877c036640775d6b30d0e98e840d07cf/lib/node_modules/%40stdlib/ndarray/ctor/lib/main.js#L57)
192192
} else {
@@ -197,10 +197,10 @@ function array() {
197197
if ( hasOwnProp( options, 'dtype' ) ) {
198198
dtype = options.dtype;
199199
if ( !isDataType( dtype ) ) {
200-
throw new TypeError( format( 'invalid option. `%s` option must be a recognized data type. Option: `%s`.', 'dtype', dtype ) );
200+
throw new TypeError( format( '0Le5O', 'dtype', dtype ) );
201201
}
202202
if ( btype && !isAllowedCast( btype, dtype, opts.casting ) ) {
203-
throw new Error( format( 'invalid option. Data type cast is not allowed. Casting mode: `%s`. From: `%s`. To: `%s`.', opts.casting, btype, dtype ) );
203+
throw new Error( format( '0Le5P', opts.casting, btype, dtype ) );
204204
}
205205
} else if ( btype ) {
206206
// TODO: reconcile difference in behavior when provided a generic array and no `dtype` option. Currently, we cast here, but do not allow casting a generic array (by default) when explicitly providing a `dtype` option.
@@ -238,7 +238,7 @@ function array() {
238238
order = defaults.order;
239239
}
240240
} else if ( !isOrder( order ) ) {
241-
throw new TypeError( format( 'invalid option. `%s` option must be a recognized order. Option: `%s`.', 'order', order ) );
241+
throw new TypeError( format( '0Le5Q', 'order', order ) );
242242
}
243243
} else {
244244
order = defaults.order;
@@ -261,7 +261,7 @@ function array() {
261261
if ( hasOwnProp( options, 'copy' ) ) {
262262
opts.copy = options.copy;
263263
if ( !isBoolean( opts.copy ) ) {
264-
throw new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'copy', opts.copy ) );
264+
throw new TypeError( format( '0Le30', 'copy', opts.copy ) );
265265
}
266266
} else {
267267
opts.copy = defaults.copy;
@@ -270,7 +270,7 @@ function array() {
270270
if ( hasOwnProp( options, 'shape' ) ) {
271271
shape = options.shape;
272272
if ( !isArrayLikeObject( shape ) ) { // weak test
273-
throw new TypeError( format( 'invalid option. `%s` option must be an array-like object containing nonnegative integers. Option: `%s`.', 'shape', shape ) );
273+
throw new TypeError( format( '0Le5R', 'shape', shape ) );
274274
}
275275
ndims = shape.length;
276276
len = numel( shape );
@@ -290,7 +290,7 @@ function array() {
290290
shape = [ len ]; // assume a 1-dimensional array (vector)
291291
}
292292
} else {
293-
throw new Error( 'invalid arguments. Must provide either a data source, array shape, or both.' );
293+
throw new Error( format( '0Le0X' ) );
294294
}
295295
// Adjust the array shape to satisfy the minimum number of dimensions...
296296
if ( ndims < opts.ndmin ) {
@@ -300,7 +300,7 @@ function array() {
300300
// If not provided a data buffer, create it; otherwise, see if we need to cast a provided data buffer to another data type or perform a copy...
301301
if ( FLG ) {
302302
if ( buffer.length !== len ) {
303-
throw new RangeError( 'invalid arguments. Array shape is incompatible with provided data source. Number of data source elements does not match array shape.' );
303+
throw new RangeError( format( '0Le0Y' ) );
304304
}
305305
if ( btype !== dtype || opts.copy ) {
306306
buffer = copyView( buffer, dtype );
@@ -318,7 +318,7 @@ function array() {
318318
buffer = flatten( buffer, osh || arrayShape( buffer ), false );
319319
}
320320
if ( buffer.length !== len ) {
321-
throw new RangeError( 'invalid arguments. Array shape is incompatible with provided data source. Number of data source elements does not match array shape.' );
321+
throw new RangeError( format( '0Le0Y' ) );
322322
}
323323
if ( btype !== dtype || opts.copy ) {
324324
buffer = castBuffer( buffer, len, dtype );

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
"@stdlib/ndarray-base-strides2order": "^0.0.6",
6363
"@stdlib/ndarray-ctor": "^0.0.10",
6464
"@stdlib/ndarray-defaults": "github:stdlib-js/ndarray-defaults#main",
65-
"@stdlib/string-format": "^0.0.3",
65+
"@stdlib/error-tools-fmtprodmsg": "^0.0.2",
6666
"@stdlib/types": "^0.0.14"
6767
},
6868
"devDependencies": {

0 commit comments

Comments
 (0)