From 7e715fb16cf3c20b852ea06ae6a4bd633251f354 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 23 Jun 2026 03:48:31 +0000 Subject: [PATCH] Transform error messages --- lib/main.js | 12 ++++++------ lib/validate.js | 6 +++--- package.json | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/main.js b/lib/main.js index 40cea2a..44fc597 100644 --- a/lib/main.js +++ b/lib/main.js @@ -31,7 +31,7 @@ var contains = require( '@stdlib/array-base-assert-contains' ); var filledBy = require( '@stdlib/array-base-filled-by' ); var binary = require( '@stdlib/strided-base-binary' ); var ctors = require( '@stdlib/array-ctors' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var validate = require( './validate.js' ); @@ -65,15 +65,15 @@ function Random( prng, dtypes, dtype ) { return new Random( prng, dtypes, dtype ); } if ( !isFunction( prng ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a function. Value: `%s`.', prng ) ); + throw new TypeError( format( '1qj3c', prng ) ); } // TODO: tighten this up by actually validating that `dtypes` contains only recognized/supported dtype strings if ( !isStringArray( dtypes ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be an array of strings. Value: `%s`.', dtypes ) ); + throw new TypeError( format( '1qjAS', dtypes ) ); } // Require that the default output array data type be a member of the list of supported output array data types... if ( !contains( dtypes, dtype ) ) { - throw new TypeError( format( 'invalid argument. Third argument must be a supported data type. Value: `%s`.', dtype ) ); + throw new TypeError( format( '1qjFO', dtype ) ); } this._prng = prng; this._dtypes = dtypes; @@ -116,7 +116,7 @@ setReadOnly( Random.prototype, 'generate', function generate( len, param1, param var err; var dt; if ( !isNonNegativeInteger( len ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a nonnegative integer. Value: `%s`.', len ) ); + throw new TypeError( format( '1qj2d', len ) ); } opts = {}; if ( arguments.length > 3 ) { @@ -179,7 +179,7 @@ setReadOnly( Random.prototype, 'generate', function generate( len, param1, param */ setReadOnly( Random.prototype, 'assign', function assign( param1, param2, out ) { if ( !isCollection( out ) ) { - throw new TypeError( format( 'invalid argument. Third argument must be an array-like object. Value: `%s`.', out ) ); + throw new TypeError( format( '1qj2l', out ) ); } // NOTE: we could alternatively use the PRNG factory function to create a nullary PRNG function which applies parameters for each invocation; however, this would impose a one-time cost which is likely to be rather expensive when filling small arrays. The decision made here avoids this cost, despite a small cost due to repeatedly validating parameters for each generated pseudorandom value. Additionally, the current implementation has the added benefit that it mirrors the underlying PRNG where invalid parameters result in, e.g., a return value of `NaN` (however, realization of this benefit depends on the output array being a floating-point array). binary( [ [ param1 ], [ param2 ], out ], [ out.length ], [ 0, 0, 1 ], this._prng ); // eslint-disable-line max-len diff --git a/lib/validate.js b/lib/validate.js index 691167c..4b4591b 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -23,7 +23,7 @@ var isObject = require( '@stdlib/assert-is-plain-object' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); var contains = require( '@stdlib/array-base-assert-contains' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -51,12 +51,12 @@ var format = require( '@stdlib/string-format' ); */ function validate( opts, dtypes, options ) { if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( '1qj2V', options ) ); } if ( hasOwnProp( options, 'dtype' ) ) { opts.dtype = options.dtype; if ( !contains( dtypes, opts.dtype ) ) { - return new TypeError( format( 'invalid option. `%s` option must be one of the following: "%s". Option: `%s`.', 'dtype', dtypes.join( '", "' ), opts.dtype ) ); + return new TypeError( format( '1qj4S', 'dtype', dtypes.join( '", "' ), opts.dtype ) ); } } return null; diff --git a/package.json b/package.json index df00eb1..231ec16 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,7 @@ "@stdlib/assert-is-plain-object": "^0.2.3", "@stdlib/assert-is-string-array": "^0.2.3", "@stdlib/strided-base-binary": "^0.3.1", - "@stdlib/string-format": "^0.2.3", + "@stdlib/error-tools-fmtprodmsg": "^0.2.3", "@stdlib/types": "^0.5.1", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.3", "@stdlib/error-tools-fmtprodmsg": "^0.2.3"