Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

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

Sign up
Appearance settings

Commit330ae85

Browse files
committed
Transform error messages
1 parent637c2ee commit330ae85

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
@@ -45,7 +45,7 @@ var getOrder = require( '@stdlib/ndarray-order' );
4545
vargetData=require('@stdlib/ndarray-data-buffer');
4646
vararrayShape=require('@stdlib/array-shape');
4747
varflatten=require('@stdlib/array-base-flatten');
48-
varformat=require('@stdlib/string-format');
48+
varformat=require('@stdlib/error-tools-fmtprodmsg');
4949
varisArrayLikeObject=require('./is_array_like_object.js');
5050
vargetDefaults=require('./defaults.js');
5151
varcastBuffer=require('./cast_buffer.js');
@@ -140,23 +140,23 @@ function array() {
140140
}else{
141141
options=arguments[0];
142142
if(!isObject(options)){
143-
thrownewTypeError(format('invalid argument. Must provide either a valid data source, options argument, or both. Value: `%s`.',options));
143+
thrownewTypeError(format('0hT56',options));
144144
}
145145
if(hasOwnProp(options,'buffer')){
146146
buffer=options.buffer;
147147
if(!isArrayLikeObject(buffer)){// weak test
148-
thrownewTypeError(format('invalid option. `%s` option must be an array-like object, typed-array-like, a Buffer, or an ndarray. Option: `%s`.','buffer',buffer));
148+
thrownewTypeError(format('0hT57','buffer',buffer));
149149
}
150150
}
151151
}
152152
}else{
153153
buffer=arguments[0];
154154
if(!isArrayLikeObject(buffer)){// weak test
155-
thrownewTypeError(format('invalid option. Data source must be an array-like object, typed-array-like, a Buffer, or an ndarray. Value: `%s`.',buffer));
155+
thrownewTypeError(format('0hT58',buffer));
156156
}
157157
options=arguments[1];
158158
if(!isObject(options)){
159-
thrownewTypeError(format('invalid argument. Options argument must be an object. Value: `%s`.',options));
159+
thrownewTypeError(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-
thrownewTypeError(format('invalid option. `%s` option must be a recognized casting mode. Option: `%s`.','casting',opts.casting));
179+
thrownewTypeError(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-
thrownewTypeError(format('invalid option. `%s` option must be a boolean. Option: `%s`.','flatten',opts.flatten));
187+
thrownewTypeError(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-
thrownewTypeError(format('invalid option. `%s` option must be a nonnegative integer. Option: `%s`.','ndmin',opts.ndmin));
195+
thrownewTypeError(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-
thrownewTypeError(format('invalid option. `%s` option must be a recognized data type. Option: `%s`.','dtype',dtype));
206+
thrownewTypeError(format('0hTBf','dtype',dtype));
207207
}
208208
if(btype&&!isAllowedCast(btype,dtype,opts.casting)){
209-
thrownewError(format('invalid option. Data type cast is not allowed. Casting mode: `%s`. From: `%s`. To: `%s`.',opts.casting,btype,dtype));
209+
thrownewError(format('0hT5B',opts.casting,btype,dtype));
210210
}
211211
}elseif(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
}elseif(!isOrder(order)){
247-
thrownewTypeError(format('invalid option. `%s` option must be a recognized order. Option: `%s`.','order',order));
247+
thrownewTypeError(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-
thrownewTypeError(format('invalid option. `%s` option must be a boolean. Option: `%s`.','copy',opts.copy));
270+
thrownewTypeError(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-
thrownewTypeError(format('invalid option. `%s` option must be an array-like object containing nonnegative integers. Option: `%s`.','shape',shape));
279+
thrownewTypeError(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-
thrownewError('invalid arguments. Must provide either a data source, array shape, or both.');
299+
thrownewError(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-
thrownewRangeError('invalid arguments. Array shape is incompatible with provided data source. Number of data source elements does not match array shape.');
309+
thrownewRangeError(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-
thrownewRangeError('invalid arguments. Array shape is incompatible with provided data source. Number of data source elements does not match array shape.');
327+
thrownewRangeError(format('0hT0Y'));
328328
}
329329
if(btype!==dtype||opts.copy){
330330
buffer=castBuffer(buffer,len,dtype);

‎package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
"@stdlib/ndarray-order":"^0.2.2",
7474
"@stdlib/ndarray-shape":"^0.2.2",
7575
"@stdlib/ndarray-strides":"^0.2.2",
76-
"@stdlib/string-format":"^0.2.2",
76+
"@stdlib/error-tools-fmtprodmsg":"^0.2.2",
7777
"@stdlib/types":"^0.4.3",
7878
"@stdlib/error-tools-fmtprodmsg":"^0.2.2"
7979
},

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp