From f0f383dbd095ebf4a29b1fae8e8c60312afac331 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 21 Sep 2025 09:27:31 +0000 Subject: [PATCH] Transform error messages --- lib/main.js | 34 +++++++++++++++++----------------- package.json | 2 +- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/lib/main.js b/lib/main.js index 29d8984..c8b8f74 100644 --- a/lib/main.js +++ b/lib/main.js @@ -27,7 +27,7 @@ var isFunctionArray = require( '@stdlib/assert-is-function-array' ); var isFunction = require( '@stdlib/assert-is-function' ); var isCollection = require( '@stdlib/assert-is-collection' ); var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var getDType = require( '@stdlib/ndarray-dtype' ); var resolveEnum = require( '@stdlib/ndarray-base-dtype-resolve-enum' ); var dtypes2enums = require( '@stdlib/ndarray-base-dtypes2enums' ); @@ -92,43 +92,43 @@ function dispatch( fcns, types, data, nargs, nin, nout ) { if ( isFunction( fcns ) ) { fcn = fcns; } else if ( !isFunctionArray( fcns ) ) { - throw new TypeError( format( 'invalid argument. First argument must be either a function or an array of functions. Value: `%s`.', fcns ) ); + throw new TypeError( format( '0jr5d', fcns ) ); } if ( !isCollection( types ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', types ) ); + throw new TypeError( format( '0jr2y', types ) ); } if ( !isCollection( data ) && data !== null ) { - throw new TypeError( format( 'invalid argument. Third argument must be an array-like object or null. Value: `%s`.', data ) ); + throw new TypeError( format( '0jr5e', data ) ); } if ( !isPositiveInteger( nargs ) ) { - throw new TypeError( format( 'invalid argument. Fourth argument must be a positive integer. Value: `%s`.', nargs ) ); + throw new TypeError( format( '0jr5f', nargs ) ); } if ( !isNonNegativeInteger( nin ) ) { - throw new TypeError( format( 'invalid argument. Fifth argument must be a nonnegative integer. Value: `%s`.', nin ) ); + throw new TypeError( format( '0jr5X', nin ) ); } if ( !isNonNegativeInteger( nout ) ) { - throw new TypeError( format( 'invalid argument. Sixth argument must be a nonnegative integer. Value: `%s`.', nout ) ); + throw new TypeError( format( '0jr5g', nout ) ); } narrays = nin + nout; if ( narrays === 0 ) { - throw new Error( 'invalid arguments. Interface must accept at least one input and/or output ndarray. Based on the provided arguments, `nin+nout` equals `0`.' ); + throw new Error( format('0jr0h') ); } if ( nargs !== narrays ) { - throw new Error( 'invalid arguments. Fourth argument does not equal the number of input and output ndarrays.' ); + throw new Error( format('0jr0i') ); } if ( fcn ) { nfcns = types.length / narrays; if ( !isInteger( nfcns ) ) { - throw new Error( 'invalid argument. Unexpected number of types. A type must be specified for each input and output ndarray for each provided ndarray function.' ); + throw new Error( format('0jr0j') ); } } else { nfcns = fcns.length; if ( types.length !== nfcns*narrays ) { - throw new Error( 'invalid argument. Unexpected number of types. A type must be specified for each input and output ndarray for each provided ndarray function.' ); + throw new Error( format('0jr0j') ); } } if ( data && data.length !== nfcns ) { - throw new Error( 'invalid argument. The third argument must have the same number of elements as the first argument.' ); + throw new Error( format('0jr0k') ); } types = dtypes2enums( types ); return dispatcher; @@ -158,9 +158,9 @@ function dispatch( fcns, types, data, nargs, nin, nout ) { argc = arguments.length; if ( argc !== nargs ) { if ( argc < nargs ) { - throw new Error( 'invalid invocation. Insufficient arguments.' ); + throw new Error( format('0jr0l') ); } - throw new Error( 'invalid invocation. Too many arguments.' ); + throw new Error( format('0jr0m') ); } arrays = []; dtypes = []; @@ -168,9 +168,9 @@ function dispatch( fcns, types, data, nargs, nin, nout ) { v = arguments[ i ]; if ( !isndarrayLike( v ) ) { if ( i < nin ) { - throw new TypeError( format( 'invalid argument. Input array must be an ndarray-like object. Value: `%s`.', v ) ); + throw new TypeError( format( '0jr5h', v ) ); } else { - throw new TypeError( format( 'invalid argument. Output array must be an ndarray-like object. Value: `%s`.', v ) ); + throw new TypeError( format( '0jr5i', v ) ); } } arrays.push( v ); @@ -181,7 +181,7 @@ function dispatch( fcns, types, data, nargs, nin, nout ) { // Check whether we were able to successfully resolve an ndarray function: if ( idx < 0 ) { - throw new TypeError( 'invalid arguments. Unable to resolve an ndarray function supporting the provided array argument data types.' ); + throw new TypeError( format('0jr0n') ); } // Retrieve the ndarray function: if ( fcn ) { diff --git a/package.json b/package.json index 0d34d20..db19487 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,7 @@ "@stdlib/ndarray-base-dtype-resolve-enum": "^0.2.2", "@stdlib/ndarray-base-dtypes2enums": "github:stdlib-js/ndarray-base-dtypes2enums#main", "@stdlib/ndarray-dtype": "^0.2.2", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/types": "^0.4.3", "@stdlib/error-tools-fmtprodmsg": "^0.2.2" },