From 7578ee594e6b877be51f98e296a578e091c51893 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 17 May 2026 13:23:03 +0000 Subject: [PATCH] chore: use `format` for error messages in strided build scripts Propagates fix from dca1108ec ("chore: use `format` for error messages in `datasets/*` build scripts") to sibling code-generation scripts that still assemble `throw new Error` messages via string concatenation. Converts `+`-concatenated error strings to `@stdlib/string/format` calls in `strided/base/binary` and `math/strided/ops/{add,sub,mul}`. --- .../@stdlib/math/strided/ops/add/scripts/addon.js | 7 ++++--- .../@stdlib/math/strided/ops/mul/scripts/addon.js | 7 ++++--- .../@stdlib/math/strided/ops/sub/scripts/addon.js | 7 ++++--- .../@stdlib/strided/base/binary/scripts/loops.js | 7 ++++--- 4 files changed, 16 insertions(+), 12 deletions(-) diff --git a/lib/node_modules/@stdlib/math/strided/ops/add/scripts/addon.js b/lib/node_modules/@stdlib/math/strided/ops/add/scripts/addon.js index ff9e792957b6..8a31bb0b3b9a 100644 --- a/lib/node_modules/@stdlib/math/strided/ops/add/scripts/addon.js +++ b/lib/node_modules/@stdlib/math/strided/ops/add/scripts/addon.js @@ -25,6 +25,7 @@ var resolve = require( 'path' ).resolve; var writeFile = require( '@stdlib/fs/write-file' ).sync; var readFile = require( '@stdlib/fs/read-file' ).sync; +var format = require( '@stdlib/string/format' ); var replace = require( '@stdlib/string/replace' ); var resolveStr = require( '@stdlib/strided/base/dtype-resolve-str' ); var dtypeChar = require( '@stdlib/ndarray/base/dtype-char' ); @@ -124,7 +125,7 @@ function main() { for ( i = 0; i < fcns.length; i++ ) { parts = fcns[ i ].match( RE_IO_ARGS ); if ( parts === null ) { - throw new Error( 'unexpected error. Unable to resolve signature dtypes. Function: `' + fcns[ i ] + '`.' ); + throw new Error( format( 'unexpected error. Unable to resolve signature dtypes. Function: `%s`.', fcns[ i ] ) ); } tmp = []; t1 = parts[ 1 ]; @@ -140,13 +141,13 @@ function main() { for ( i = 0; i < fcns.length; i++ ) { parts = fcns[ i ].match( RE_CLBK_ARGS ); if ( parts === null ) { - throw new Error( 'unexpected error. Unable to resolve signature dtypes. Function: `' + fcns[ i ] + '`.' ); + throw new Error( format( 'unexpected error. Unable to resolve signature dtypes. Function: `%s`.', fcns[ i ] ) ); } t1 = parts[ 1 ]; t2 = parts[ 2 ]; t3 = parts[ 3 ]; if ( t1 !== t2 || t2 !== t3 ) { - throw new Error( 'unexpected error. Callback arguments must all be the same. Function: `' + fcns[ i ] + '`.' ); + throw new Error( format( 'unexpected error. Callback arguments must all be the same. Function: `%s`.', fcns[ i ] ) ); } if ( t1 === FLOAT64_CHAR ) { f = 'stdlib_base_float64_'+FCN_BASENAME; diff --git a/lib/node_modules/@stdlib/math/strided/ops/mul/scripts/addon.js b/lib/node_modules/@stdlib/math/strided/ops/mul/scripts/addon.js index 7f2322b95eab..1f05537da1a4 100644 --- a/lib/node_modules/@stdlib/math/strided/ops/mul/scripts/addon.js +++ b/lib/node_modules/@stdlib/math/strided/ops/mul/scripts/addon.js @@ -25,6 +25,7 @@ var resolve = require( 'path' ).resolve; var writeFile = require( '@stdlib/fs/write-file' ).sync; var readFile = require( '@stdlib/fs/read-file' ).sync; +var format = require( '@stdlib/string/format' ); var replace = require( '@stdlib/string/replace' ); var resolveStr = require( '@stdlib/strided/base/dtype-resolve-str' ); var dtypeChar = require( '@stdlib/ndarray/base/dtype-char' ); @@ -124,7 +125,7 @@ function main() { for ( i = 0; i < fcns.length; i++ ) { parts = fcns[ i ].match( RE_IO_ARGS ); if ( parts === null ) { - throw new Error( 'unexpected error. Unable to resolve signature dtypes. Function: `' + fcns[ i ] + '`.' ); + throw new Error( format( 'unexpected error. Unable to resolve signature dtypes. Function: `%s`.', fcns[ i ] ) ); } tmp = []; t1 = parts[ 1 ]; @@ -140,13 +141,13 @@ function main() { for ( i = 0; i < fcns.length; i++ ) { parts = fcns[ i ].match( RE_CLBK_ARGS ); if ( parts === null ) { - throw new Error( 'unexpected error. Unable to resolve signature dtypes. Function: `' + fcns[ i ] + '`.' ); + throw new Error( format( 'unexpected error. Unable to resolve signature dtypes. Function: `%s`.', fcns[ i ] ) ); } t1 = parts[ 1 ]; t2 = parts[ 2 ]; t3 = parts[ 3 ]; if ( t1 !== t2 || t2 !== t3 ) { - throw new Error( 'unexpected error. Callback arguments must all be the same. Function: `' + fcns[ i ] + '`.' ); + throw new Error( format( 'unexpected error. Callback arguments must all be the same. Function: `%s`.', fcns[ i ] ) ); } if ( t1 === FLOAT64_CHAR ) { f = 'stdlib_base_float64_'+FCN_BASENAME; diff --git a/lib/node_modules/@stdlib/math/strided/ops/sub/scripts/addon.js b/lib/node_modules/@stdlib/math/strided/ops/sub/scripts/addon.js index e06dc376c722..a52c4bdcf1f0 100644 --- a/lib/node_modules/@stdlib/math/strided/ops/sub/scripts/addon.js +++ b/lib/node_modules/@stdlib/math/strided/ops/sub/scripts/addon.js @@ -25,6 +25,7 @@ var resolve = require( 'path' ).resolve; var writeFile = require( '@stdlib/fs/write-file' ).sync; var readFile = require( '@stdlib/fs/read-file' ).sync; +var format = require( '@stdlib/string/format' ); var replace = require( '@stdlib/string/replace' ); var resolveStr = require( '@stdlib/strided/base/dtype-resolve-str' ); var dtypeChar = require( '@stdlib/ndarray/base/dtype-char' ); @@ -124,7 +125,7 @@ function main() { for ( i = 0; i < fcns.length; i++ ) { parts = fcns[ i ].match( RE_IO_ARGS ); if ( parts === null ) { - throw new Error( 'unexpected error. Unable to resolve signature dtypes. Function: `' + fcns[ i ] + '`.' ); + throw new Error( format( 'unexpected error. Unable to resolve signature dtypes. Function: `%s`.', fcns[ i ] ) ); } tmp = []; t1 = parts[ 1 ]; @@ -140,13 +141,13 @@ function main() { for ( i = 0; i < fcns.length; i++ ) { parts = fcns[ i ].match( RE_CLBK_ARGS ); if ( parts === null ) { - throw new Error( 'unexpected error. Unable to resolve signature dtypes. Function: `' + fcns[ i ] + '`.' ); + throw new Error( format( 'unexpected error. Unable to resolve signature dtypes. Function: `%s`.', fcns[ i ] ) ); } t1 = parts[ 1 ]; t2 = parts[ 2 ]; t3 = parts[ 3 ]; if ( t1 !== t2 || t2 !== t3 ) { - throw new Error( 'unexpected error. Callback arguments must all be the same. Function: `' + fcns[ i ] + '`.' ); + throw new Error( format( 'unexpected error. Callback arguments must all be the same. Function: `%s`.', fcns[ i ] ) ); } if ( t1 === FLOAT64_CHAR ) { f = 'stdlib_base_float64_'+FCN_BASENAME; diff --git a/lib/node_modules/@stdlib/strided/base/binary/scripts/loops.js b/lib/node_modules/@stdlib/strided/base/binary/scripts/loops.js index 73189089698c..5d7ce39b3bfe 100644 --- a/lib/node_modules/@stdlib/strided/base/binary/scripts/loops.js +++ b/lib/node_modules/@stdlib/strided/base/binary/scripts/loops.js @@ -29,6 +29,7 @@ var unlink = require( '@stdlib/fs/unlink' ).sync; var readFile = require( '@stdlib/fs/read-file' ).sync; var readJSON = require( '@stdlib/fs/read-json' ).sync; var writeFile = require( '@stdlib/fs/write-file' ).sync; +var format = require( '@stdlib/string/format' ); var replace = require( '@stdlib/string/replace' ); var substringBefore = require( '@stdlib/string/substring-before' ); var substringAfter = require( '@stdlib/string/substring-after' ); @@ -453,7 +454,7 @@ function createSourceFile( signature ) { if ( isComplexChar( ch1 ) ) { // WARNING: we assume that the callback signature has the same complex number dtype for all input and output values and that the output array dtype is a complex number dtype... if ( !isComplexChar( match1[ 3 ] ) ) { - throw new Error( 'unexpected error. Unable to process signature: '+signature+'.' ); + throw new Error( format( 'unexpected error. Unable to process signature: %s.', signature ) ); } macro = MACROS.acast; if ( ch1 === 'z' ) { @@ -470,7 +471,7 @@ function createSourceFile( signature ) { args.push( 'stdlib_complex64_from_'+t3 ); } } else if ( isComplexChar( ch2 ) || isComplexChar( ch3 ) ) { - throw new Error( 'unexpected error. Unable to process callback signature: '+ch1+ch2+'_'+ch3+'.' ); + throw new Error( format( 'unexpected error. Unable to process callback signature: %s%s_%s.', ch1, ch2, ch3 ) ); } else { macro = MACROS.cast; args.push( ct1, ct2 ); @@ -478,7 +479,7 @@ function createSourceFile( signature ) { } else if ( /[cz]/.test( signature ) ) { // E.g., zz_z, cc_c, cc_z, ff_c, dd_z, uu_z, ##_(c|z), etc. For all these signatures, the callback signature is expected to be ##_#, meaning all the same dtype (e.g., uu_u). if ( ch1 !== ch2 ) { - throw new Error( 'unexpected error. Unable to process signature: '+ch1+ch2+'_'+ch3+'.' ); + throw new Error( format( 'unexpected error. Unable to process signature: %s%s_%s.', ch1, ch2, ch3 ) ); } if ( ch1 === ch2 && ch2 === ch3 ) { // e.g., zz_z, cc_c macro = MACROS.nocast;