Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 69d8feb

Browse filesBrowse files
committed
Transform error messages
1 parent 67f5719 commit 69d8feb
Copy full SHA for 69d8feb

File tree

2 files changed

+17
-17
lines changed
Filter options

2 files changed

+17
-17
lines changed

‎lib/main.js

Copy file name to clipboardExpand all lines: lib/main.js
+16-16Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ var getOrder = require( '@stdlib/ndarray-order' );
4545
var getData = require( '@stdlib/ndarray-data-buffer' );
4646
var arrayShape = require( '@stdlib/array-shape' );
4747
var flatten = require( '@stdlib/array-base-flatten' );
48-
var format = require( '@stdlib/string-format' );
48+
var format = require( '@stdlib/error-tools-fmtprodmsg' );
4949
var isArrayLikeObject = require( './is_array_like_object.js' );
5050
var getDefaults = require( './defaults.js' );
5151
var castBuffer = require( './cast_buffer.js' );
@@ -140,23 +140,23 @@ function array() {
140140
} else {
141141
options = arguments[ 0 ];
142142
if ( !isObject( options ) ) {
143-
throw new TypeError( format( 'invalid argument. Must provide either a valid data source, options argument, or both. Value: `%s`.', options ) );
143+
throw new TypeError( format( '0hT56', options ) );
144144
}
145145
if ( hasOwnProp( options, 'buffer' ) ) {
146146
buffer = options.buffer;
147147
if ( !isArrayLikeObject( buffer ) ) { // weak test
148-
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 ) );
148+
throw new TypeError( format( '0hT57', 'buffer', buffer ) );
149149
}
150150
}
151151
}
152152
} else {
153153
buffer = arguments[ 0 ];
154154
if ( !isArrayLikeObject( buffer ) ) { // weak test
155-
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 ) );
155+
throw new TypeError( format( '0hT58', buffer ) );
156156
}
157157
options = arguments[ 1 ];
158158
if ( !isObject( options ) ) {
159-
throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );
159+
throw new TypeError( format( '0hT2V', options ) );
160160
}
161161
// Note: we ignore whether `options` has a `buffer` property
162162
}
@@ -176,23 +176,23 @@ function array() {
176176
if ( hasOwnProp( options, 'casting' ) ) {
177177
opts.casting = options.casting;
178178
if ( !isCastingMode( opts.casting ) ) {
179-
throw new TypeError( format( 'invalid option. `%s` option must be a recognized casting mode. Option: `%s`.', 'casting', opts.casting ) );
179+
throw new TypeError( format( '0hT59', 'casting', opts.casting ) );
180180
}
181181
} else {
182182
opts.casting = defaults.casting;
183183
}
184184
if ( hasOwnProp( options, 'flatten' ) ) {
185185
opts.flatten = options.flatten;
186186
if ( !isBoolean( opts.flatten ) ) {
187-
throw new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'flatten', opts.flatten ) );
187+
throw new TypeError( format( '0hT2o', 'flatten', opts.flatten ) );
188188
}
189189
} else {
190190
opts.flatten = defaults.flatten;
191191
}
192192
if ( hasOwnProp( options, 'ndmin' ) ) {
193193
opts.ndmin = options.ndmin;
194194
if ( !isNonNegativeInteger( opts.ndmin ) ) {
195-
throw new TypeError( format( 'invalid option. `%s` option must be a nonnegative integer. Option: `%s`.', 'ndmin', opts.ndmin ) );
195+
throw new TypeError( format( '0hT2t', 'ndmin', opts.ndmin ) );
196196
}
197197
// 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)
198198
} else {
@@ -203,10 +203,10 @@ function array() {
203203
if ( hasOwnProp( options, 'dtype' ) ) {
204204
dtype = options.dtype;
205205
if ( !isDataType( dtype ) ) {
206-
throw new TypeError( format( 'invalid option. `%s` option must be a recognized data type. Option: `%s`.', 'dtype', dtype ) );
206+
throw new TypeError( format( '0hTBf', 'dtype', dtype ) );
207207
}
208208
if ( btype && !isAllowedCast( btype, dtype, opts.casting ) ) {
209-
throw new Error( format( 'invalid option. Data type cast is not allowed. Casting mode: `%s`. From: `%s`. To: `%s`.', opts.casting, btype, dtype ) );
209+
throw new Error( format( '0hT5B', opts.casting, btype, dtype ) );
210210
}
211211
} else if ( btype ) { // btype !== void 0
212212
// 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.
@@ -244,7 +244,7 @@ function array() {
244244
order = defaults.order;
245245
}
246246
} else if ( !isOrder( order ) ) {
247-
throw new TypeError( format( 'invalid option. `%s` option must be a recognized order. Option: `%s`.', 'order', order ) );
247+
throw new TypeError( format( '0hT5C', 'order', order ) );
248248
}
249249
} else {
250250
order = defaults.order;
@@ -267,7 +267,7 @@ function array() {
267267
if ( hasOwnProp( options, 'copy' ) ) {
268268
opts.copy = options.copy;
269269
if ( !isBoolean( opts.copy ) ) {
270-
throw new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'copy', opts.copy ) );
270+
throw new TypeError( format( '0hT2o', 'copy', opts.copy ) );
271271
}
272272
} else {
273273
opts.copy = defaults.copy;
@@ -276,7 +276,7 @@ function array() {
276276
if ( hasOwnProp( options, 'shape' ) ) {
277277
shape = options.shape;
278278
if ( !isArrayLikeObject( shape ) ) { // weak test
279-
throw new TypeError( format( 'invalid option. `%s` option must be an array-like object containing nonnegative integers. Option: `%s`.', 'shape', shape ) );
279+
throw new TypeError( format( '0hT5D', 'shape', shape ) );
280280
}
281281
ndims = shape.length;
282282
len = numel( shape );
@@ -296,7 +296,7 @@ function array() {
296296
shape = [ len ]; // assume a 1-dimensional array (vector)
297297
}
298298
} else {
299-
throw new Error( 'invalid arguments. Must provide either a data source, array shape, or both.' );
299+
throw new Error( format('0hT0X') );
300300
}
301301
// Adjust the array shape to satisfy the minimum number of dimensions...
302302
if ( ndims < opts.ndmin ) {
@@ -306,7 +306,7 @@ function array() {
306306
// 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...
307307
if ( FLG ) {
308308
if ( numel( buffer.shape ) !== len ) {
309-
throw new RangeError( 'invalid arguments. Array shape is incompatible with provided data source. Number of data source elements does not match array shape.' );
309+
throw new RangeError( format('0hT0Y') );
310310
}
311311
if ( btype !== dtype || opts.copy ) {
312312
buffer = copyView( buffer, dtype );
@@ -324,7 +324,7 @@ function array() {
324324
buffer = flatten( buffer, osh || arrayShape( buffer ), order === 'column-major' );
325325
}
326326
if ( buffer.length !== len ) {
327-
throw new RangeError( 'invalid arguments. Array shape is incompatible with provided data source. Number of data source elements does not match array shape.' );
327+
throw new RangeError( format('0hT0Y') );
328328
}
329329
if ( btype !== dtype || opts.copy ) {
330330
buffer = castBuffer( buffer, len, dtype );

‎package.json

Copy file name to clipboardExpand all lines: package.json
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
"@stdlib/ndarray-order": "^0.2.2",
7373
"@stdlib/ndarray-shape": "^0.2.2",
7474
"@stdlib/ndarray-strides": "^0.2.2",
75-
"@stdlib/string-format": "^0.2.2",
75+
"@stdlib/error-tools-fmtprodmsg": "^0.2.2",
7676
"@stdlib/types": "^0.4.3",
7777
"@stdlib/error-tools-fmtprodmsg": "^0.2.2"
7878
},

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.