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

Commit4fe818f

Browse files
committed
Transform error messages
1 parent728bfae commit4fe818f

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
@@ -46,7 +46,7 @@ var getOrder = require( '@stdlib/ndarray-order' );
4646
vargetData=require('@stdlib/ndarray-data-buffer');
4747
vararrayShape=require('@stdlib/array-shape');
4848
varflatten=require('@stdlib/array-base-flatten');
49-
varformat=require('@stdlib/string-format');
49+
varformat=require('@stdlib/error-tools-fmtprodmsg');
5050
varisArrayLikeObject=require('./is_array_like_object.js');
5151
vargetDefaults=require('./defaults.js');
5252
varcastBuffer=require('./cast_buffer.js');
@@ -141,23 +141,23 @@ function array() {
141141
}else{
142142
options=arguments[0];
143143
if(!isObject(options)){
144-
thrownewTypeError(format('invalid argument. Must provide either a valid data source, options argument, or both. Value: `%s`.',options));
144+
thrownewTypeError(format('0hT56',options));
145145
}
146146
if(hasOwnProp(options,'buffer')){
147147
buffer=options.buffer;
148148
if(!isArrayLikeObject(buffer)){// weak test
149-
thrownewTypeError(format('invalid option. `%s` option must be an array-like object, typed-array-like, a Buffer, or an ndarray. Option: `%s`.','buffer',buffer));
149+
thrownewTypeError(format('0hT57','buffer',buffer));
150150
}
151151
}
152152
}
153153
}else{
154154
buffer=arguments[0];
155155
if(!isArrayLikeObject(buffer)){// weak test
156-
thrownewTypeError(format('invalid option. Data source must be an array-like object, typed-array-like, a Buffer, or an ndarray. Value: `%s`.',buffer));
156+
thrownewTypeError(format('0hT58',buffer));
157157
}
158158
options=arguments[1];
159159
if(!isObject(options)){
160-
thrownewTypeError(format('invalid argument. Options argument must be an object. Value: `%s`.',options));
160+
thrownewTypeError(format('0hT2V',options));
161161
}
162162
// Note: we ignore whether `options` has a `buffer` property
163163
}
@@ -177,23 +177,23 @@ function array() {
177177
if(hasOwnProp(options,'casting')){
178178
opts.casting=options.casting;
179179
if(!isCastingMode(opts.casting)){
180-
thrownewTypeError(format('invalid option. `%s` option must be a recognized casting mode. Option: `%s`.','casting',opts.casting));
180+
thrownewTypeError(format('0hT59','casting',opts.casting));
181181
}
182182
}else{
183183
opts.casting=defaults.casting;
184184
}
185185
if(hasOwnProp(options,'flatten')){
186186
opts.flatten=options.flatten;
187187
if(!isBoolean(opts.flatten)){
188-
thrownewTypeError(format('invalid option. `%s` option must be a boolean. Option: `%s`.','flatten',opts.flatten));
188+
thrownewTypeError(format('0hT2o','flatten',opts.flatten));
189189
}
190190
}else{
191191
opts.flatten=defaults.flatten;
192192
}
193193
if(hasOwnProp(options,'ndmin')){
194194
opts.ndmin=options.ndmin;
195195
if(!isNonNegativeInteger(opts.ndmin)){
196-
thrownewTypeError(format('invalid option. `%s` option must be a nonnegative integer. Option: `%s`.','ndmin',opts.ndmin));
196+
thrownewTypeError(format('0hT2t','ndmin',opts.ndmin));
197197
}
198198
// 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)
199199
}else{
@@ -204,10 +204,10 @@ function array() {
204204
if(hasOwnProp(options,'dtype')){
205205
dtype=options.dtype;
206206
if(!isDataType(dtype)){
207-
thrownewTypeError(format('invalid option. `%s` option must be a recognized data type. Option: `%s`.','dtype',dtype));
207+
thrownewTypeError(format('0hTBf','dtype',dtype));
208208
}
209209
if(btype&&!isAllowedCast(btype,dtype,opts.casting)){
210-
thrownewError(format('invalid option. Data type cast is not allowed. Casting mode: `%s`. From: `%s`. To: `%s`.',opts.casting,btype,dtype));
210+
thrownewError(format('0hT5B',opts.casting,btype,dtype));
211211
}
212212
}elseif(btype){// btype !== void 0
213213
// 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.
@@ -245,7 +245,7 @@ function array() {
245245
order=defaults.order;
246246
}
247247
}elseif(!isOrder(order)){
248-
thrownewTypeError(format('invalid option. `%s` option must be a recognized order. Option: `%s`.','order',order));
248+
thrownewTypeError(format('0hT5C','order',order));
249249
}
250250
}else{
251251
order=defaults.order;
@@ -268,7 +268,7 @@ function array() {
268268
if(hasOwnProp(options,'copy')){
269269
opts.copy=options.copy;
270270
if(!isBoolean(opts.copy)){
271-
thrownewTypeError(format('invalid option. `%s` option must be a boolean. Option: `%s`.','copy',opts.copy));
271+
thrownewTypeError(format('0hT2o','copy',opts.copy));
272272
}
273273
}else{
274274
opts.copy=defaults.copy;
@@ -277,7 +277,7 @@ function array() {
277277
if(hasOwnProp(options,'shape')){
278278
shape=options.shape;
279279
if(!isArrayLikeObject(shape)){// weak test
280-
thrownewTypeError(format('invalid option. `%s` option must be an array-like object containing nonnegative integers. Option: `%s`.','shape',shape));
280+
thrownewTypeError(format('0hT5D','shape',shape));
281281
}
282282
ndims=shape.length;
283283
len=numel(shape);
@@ -297,7 +297,7 @@ function array() {
297297
shape=[len];// assume a 1-dimensional array (vector)
298298
}
299299
}else{
300-
thrownewError('invalid arguments. Must provide either a data source, array shape, or both.');
300+
thrownewError(format('0hT0X'));
301301
}
302302
// Adjust the array shape to satisfy the minimum number of dimensions...
303303
if(ndims<opts.ndmin){
@@ -307,7 +307,7 @@ function array() {
307307
// 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...
308308
if(FLG){
309309
if(numel(buffer.shape)!==len){
310-
thrownewRangeError('invalid arguments. Array shape is incompatible with provided data source. Number of data source elements does not match array shape.');
310+
thrownewRangeError(format('0hT0Y'));
311311
}
312312
if(btype!==dtype||opts.copy){
313313
buffer=copyView(buffer,dtype);
@@ -325,7 +325,7 @@ function array() {
325325
buffer=flatten(buffer,osh||arrayShape(buffer),isColumnMajor(order));
326326
}
327327
if(buffer.length!==len){
328-
thrownewRangeError('invalid arguments. Array shape is incompatible with provided data source. Number of data source elements does not match array shape.');
328+
thrownewRangeError(format('0hT0Y'));
329329
}
330330
if(btype!==dtype||opts.copy){
331331
buffer=castBuffer(buffer,len,dtype);

‎package.json‎

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

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp