From c82a550d6408b275d6d25da7154335372963c0e7 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 12 Apr 2024 03:59:25 +0000 Subject: [PATCH] Transform error messages --- lib/from_adjacency_list_iterator.js | 4 +- lib/from_adjacency_list_iterator_map.js | 4 +- lib/from_edges_iterator.js | 4 +- lib/from_edges_iterator_map.js | 4 +- lib/main.js | 74 ++++++++++++------------- package.json | 2 +- 6 files changed, 46 insertions(+), 46 deletions(-) diff --git a/lib/from_adjacency_list_iterator.js b/lib/from_adjacency_list_iterator.js index d6b231a..c918f59 100644 --- a/lib/from_adjacency_list_iterator.js +++ b/lib/from_adjacency_list_iterator.js @@ -21,7 +21,7 @@ // MODULES // var isCollection = require( '@stdlib/assert-is-collection' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -44,7 +44,7 @@ function fromIterator( it ) { z = v.value; if ( z ) { if ( !isCollection( z ) ) { - return new TypeError( format( 'invalid argument. An iterator must return an array-like object containing vertices. Value: `%s`.', z ) ); + return new TypeError( format( '1S9Ao', z ) ); } out.push( z ); } diff --git a/lib/from_adjacency_list_iterator_map.js b/lib/from_adjacency_list_iterator_map.js index 8df174b..c4335b4 100644 --- a/lib/from_adjacency_list_iterator_map.js +++ b/lib/from_adjacency_list_iterator_map.js @@ -21,7 +21,7 @@ // MODULES // var isCollection = require( '@stdlib/assert-is-collection' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -50,7 +50,7 @@ function fromIteratorMap( it, clbk, thisArg ) { if ( z ) { z = clbk.call( thisArg, z, i ); if ( !isCollection( z ) ) { - return new TypeError( format( 'invalid argument. Callback must return an array-like object containing vertices. Value: `%s`.', z ) ); + return new TypeError( format( '1S9Ap', z ) ); } out.push( z ); } diff --git a/lib/from_edges_iterator.js b/lib/from_edges_iterator.js index 5d2af24..5b2e8c8 100644 --- a/lib/from_edges_iterator.js +++ b/lib/from_edges_iterator.js @@ -21,7 +21,7 @@ // MODULES // var isCollection = require( '@stdlib/assert-is-collection' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -44,7 +44,7 @@ function fromIterator( it ) { z = v.value; if ( z ) { if ( !isCollection( z ) ) { - return new TypeError( format( 'invalid argument. An iterator must return an array-like object containing vertices. Value: `%s`.', z ) ); + return new TypeError( format( '1S9Ao', z ) ); } out.push( z[ 0 ], z[ 1 ] ); } diff --git a/lib/from_edges_iterator_map.js b/lib/from_edges_iterator_map.js index cef511f..bd64684 100644 --- a/lib/from_edges_iterator_map.js +++ b/lib/from_edges_iterator_map.js @@ -21,7 +21,7 @@ // MODULES // var isCollection = require( '@stdlib/assert-is-collection' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -50,7 +50,7 @@ function fromIteratorMap( it, clbk, thisArg ) { if ( z ) { z = clbk.call( thisArg, z, i ); if ( !isCollection( z ) ) { - return new TypeError( format( 'invalid argument. Callback must return an array-like object containing vertices. Value: `%s`.', z ) ); + return new TypeError( format( '1S9Ap', z ) ); } out.push( z[ 0 ], z[ 1 ] ); } diff --git a/lib/main.js b/lib/main.js index 6b221a0..bda3989 100644 --- a/lib/main.js +++ b/lib/main.js @@ -33,7 +33,7 @@ var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-propert var setReadOnlyAccessor = require( '@stdlib/utils-define-nonenumerable-read-only-accessor' ); var Int32Array = require( '@stdlib/array-int32' ); var Int8Array = require( '@stdlib/array-int8' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var ceil = require( '@stdlib/math-base-special-ceil' ); var floor = require( '@stdlib/math-base-special-floor' ); var grev = require( '@stdlib/blas-ext-base-grev' ); @@ -77,7 +77,7 @@ function CompactAdjacencyMatrix( N ) { return new CompactAdjacencyMatrix( N ); } if ( !isNonNegativeInteger( N ) ) { - throw new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', N ) ); + throw new TypeError( format( '1S92K', N ) ); } this._N = N; // number of vertices this._M = 0; // number of edges @@ -133,16 +133,16 @@ setReadOnly( CompactAdjacencyMatrix, 'fromAdjacencyList', function fromAdjacency var i; var j; if ( !isFunction( this ) ) { - throw new TypeError( 'invalid invocation. `this` context must be a constructor.' ); + throw new TypeError( format('1S901') ); } if ( this !== CompactAdjacencyMatrix ) { - throw new TypeError( 'invalid invocation. `this` is not a compact adjacency matrix.' ); + throw new TypeError( format('1S91c') ); } nargs = arguments.length; if ( nargs > 1 ) { clbk = arguments[ 1 ]; if ( !isFunction( clbk ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be a function. Value: `%s`.', clbk ) ); + throw new TypeError( format( '1S92H', clbk ) ); } if ( nargs > 2 ) { thisArg = arguments[ 2 ]; @@ -155,7 +155,7 @@ setReadOnly( CompactAdjacencyMatrix, 'fromAdjacencyList', function fromAdjacency for ( i = 0; i < N; i++ ) { edges = clbk.call( thisArg, list[ i ], i ); if ( !isCollection( edges ) ) { - throw new TypeError( format( 'invalid argument. Callback must return an array-like object. Value: `%s`.', edges ) ); + throw new TypeError( format( '1S9Aq', edges ) ); } for ( j = 0; j < edges.length; j++ ) { adj.addEdge( i, edges[ j ] ); @@ -166,7 +166,7 @@ setReadOnly( CompactAdjacencyMatrix, 'fromAdjacencyList', function fromAdjacency for ( i = 0; i < N; i++ ) { edges = list[ i ]; if ( !isCollection( edges ) ) { - throw new TypeError( format( 'invalid argument. Each element of the adjacency list must be an array-like object. Value: `%s`.', list ) ); + throw new TypeError( format( '1S9Ar', list ) ); } for ( j = 0; j < edges.length; j++ ) { adj.addEdge( i, edges[ j ] ); @@ -177,7 +177,7 @@ setReadOnly( CompactAdjacencyMatrix, 'fromAdjacencyList', function fromAdjacency if ( isObject( list ) && HAS_ITERATOR_SYMBOL && isFunction( list[ ITERATOR_SYMBOL ] ) ) { // eslint-disable-line max-len tmp = list[ ITERATOR_SYMBOL ](); if ( !isFunction( tmp.next ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an array-like object or an iterable. Value: `%s`.', list ) ); + throw new TypeError( format( '1S92J', list ) ); } if ( clbk ) { tmp = fromIteratorAdjListMap( tmp, clbk, thisArg ); @@ -197,7 +197,7 @@ setReadOnly( CompactAdjacencyMatrix, 'fromAdjacencyList', function fromAdjacency } return adj; } - throw new TypeError( format( 'invalid argument. First argument must be an array-like object or an iterable. Value: `%s`.', list ) ); + throw new TypeError( format( '1S92J', list ) ); }); /** @@ -248,23 +248,23 @@ setReadOnly( CompactAdjacencyMatrix, 'fromEdges', function fromEdges( N, edges ) var len; var i; if ( !isFunction( this ) ) { - throw new TypeError( 'invalid invocation. `this` context must be a constructor.' ); + throw new TypeError( format('1S901') ); } if ( this !== CompactAdjacencyMatrix ) { - throw new TypeError( 'invalid invocation. `this` is not a compact adjacency matrix.' ); + throw new TypeError( format('1S91c') ); } nargs = arguments.length; if ( nargs > 2 ) { clbk = arguments[ 2 ]; if ( !isFunction( clbk ) ) { - throw new TypeError( format( 'invalid argument. Third argument must be a function. Value: `%s`.', clbk ) ); + throw new TypeError( format( '1S93N', clbk ) ); } if ( nargs > 3 ) { thisArg = arguments[ 3 ]; } } if ( !isNonNegativeInteger( N ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a nonnegative integer. Value: `%s`.', N ) ); + throw new TypeError( format( '1S92d', N ) ); } if ( isArrayLikeObject( edges ) ) { if ( clbk ) { @@ -272,7 +272,7 @@ setReadOnly( CompactAdjacencyMatrix, 'fromEdges', function fromEdges( N, edges ) for ( i = 0; i < edges.length; i++ ) { edge = clbk.call( thisArg, edges[ i ], i ); if ( !isArrayLikeObject( edge ) ) { - throw new TypeError( format( 'invalid argument. Callback must return an array-like object. Value: `%s`.', edge ) ); + throw new TypeError( format( '1S9Aq', edge ) ); } adj.addEdge( edge[ 0 ], edge[ 1 ] ); } @@ -282,7 +282,7 @@ setReadOnly( CompactAdjacencyMatrix, 'fromEdges', function fromEdges( N, edges ) for ( i = 0; i < edges.length; i++ ) { edge = edges[ i ]; if ( !isArrayLikeObject( edge ) ) { - throw new TypeError( format( 'invalid argument. Each element of the edge list must be an array-like object. Value: `%s`.', edge ) ); + throw new TypeError( format( '1S9As', edge ) ); } adj.addEdge( edge[ 0 ], edge[ 1 ] ); } @@ -292,7 +292,7 @@ setReadOnly( CompactAdjacencyMatrix, 'fromEdges', function fromEdges( N, edges ) if ( isObject( edges ) && HAS_ITERATOR_SYMBOL && isFunction( edges[ ITERATOR_SYMBOL ] ) ) { // eslint-disable-line max-len tmp = edges[ ITERATOR_SYMBOL ](); if ( !isFunction( tmp.next ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an array-like object or an iterable. Value: `%s`.', edges ) ); + throw new TypeError( format( '1S92J', edges ) ); } if ( clbk ) { tmp = fromIteratorEdgesMap( tmp, clbk, thisArg ); @@ -309,7 +309,7 @@ setReadOnly( CompactAdjacencyMatrix, 'fromEdges', function fromEdges( N, edges ) } return adj; } - throw new TypeError( format( 'invalid argument. Second argument must be an array-like object or an iterable. Value: `%s`.', edges ) ); + throw new TypeError( format( '1S9At', edges ) ); }); /** @@ -375,16 +375,16 @@ setReadOnly( CompactAdjacencyMatrix.prototype, '_loc', function loc( i, j, out ) setReadOnly( CompactAdjacencyMatrix.prototype, 'addEdge', function addEdge( i, j ) { var idx; if ( !isNonNegativeInteger( i ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a nonnegative integer. Value: `%s`.', i ) ); + throw new TypeError( format( '1S92d', i ) ); } if ( !isNonNegativeInteger( j ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', j ) ); + throw new TypeError( format( '1S93X', j ) ); } if ( i >= this._N ) { - throw new RangeError( format( 'invalid argument. First argument exceeds matrix dimensions. Value: `%u`.', i ) ); + throw new RangeError( format( '1S9Au', i ) ); } if ( j >= this._N ) { - throw new RangeError( format( 'invalid argument. Second argument exceeds matrix dimensions. Value: `%u`.', j ) ); + throw new RangeError( format( '1S9Av', j ) ); } // Resolve the `(i,j)` pair: idx = this._loc( i, j, [ 0, 0 ] ); @@ -481,16 +481,16 @@ setReadOnlyAccessor( CompactAdjacencyMatrix.prototype, 'edges', function edges() setReadOnly( CompactAdjacencyMatrix.prototype, 'hasEdge', function hasEdge( i, j ) { var idx; if ( !isNonNegativeInteger( i ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a nonnegative integer. Value: `%s`.', i ) ); + throw new TypeError( format( '1S92d', i ) ); } if ( !isNonNegativeInteger( j ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', j ) ); + throw new TypeError( format( '1S93X', j ) ); } if ( i >= this._N ) { - throw new RangeError( format( 'invalid argument. First argument exceeds matrix dimensions. Value: `%u`.', i ) ); + throw new RangeError( format( '1S9Au', i ) ); } if ( j >= this._N ) { - throw new RangeError( format( 'invalid argument. Second argument exceeds matrix dimensions. Value: `%u`.', j ) ); + throw new RangeError( format( '1S9Av', j ) ); } // Resolve the `(i,j)` pair: idx = this._loc( i, j, [ 0, 0 ] ); @@ -530,10 +530,10 @@ setReadOnly( CompactAdjacencyMatrix.prototype, 'inDegree', function inDegree( j var idx; var i; if ( !isNonNegativeInteger( j ) ) { - throw new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', j ) ); + throw new TypeError( format( '1S92K', j ) ); } if ( j >= this._N ) { - throw new RangeError( format( 'invalid argument. Vertex cannot exceed matrix dimensions. Value: `%u`.', j ) ); + throw new RangeError( format( '1S9Aw', j ) ); } // Iterate over the rows and add up the number of edges... deg = 0; @@ -579,10 +579,10 @@ setReadOnly( CompactAdjacencyMatrix.prototype, 'inEdges', function inEdges( j ) var idx; var i; if ( !isNonNegativeInteger( j ) ) { - throw new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', j ) ); + throw new TypeError( format( '1S92K', j ) ); } if ( j >= this._N ) { - throw new RangeError( format( 'invalid argument. Vertex cannot exceed matrix dimensions. Value: `%u`.', j ) ); + throw new RangeError( format( '1S9Aw', j ) ); } // Iterate over the rows and retrieve edges... edges = []; @@ -678,10 +678,10 @@ setReadOnly( CompactAdjacencyMatrix.prototype, 'outDegree', function outDegree( var idx; var j; if ( !isNonNegativeInteger( i ) ) { - throw new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', i ) ); + throw new TypeError( format( '1S92K', i ) ); } if ( i >= this._N ) { - throw new RangeError( format( 'invalid argument. Vertex cannot exceed matrix dimensions. Value: `%u`.', i ) ); + throw new RangeError( format( '1S9Aw', i ) ); } // Iterate over the columns and add up the number of edges... deg = 0; @@ -727,10 +727,10 @@ setReadOnly( CompactAdjacencyMatrix.prototype, 'outEdges', function outEdges( i var idx; var j; if ( !isNonNegativeInteger( i ) ) { - throw new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', i ) ); + throw new TypeError( format( '1S92K', i ) ); } if ( i >= this._N ) { - throw new RangeError( format( 'invalid argument. Vertex cannot exceed matrix dimensions. Value: `%u`.', i ) ); + throw new RangeError( format( '1S9Aw', i ) ); } // Iterate over the rows and retrieve edges... edges = []; @@ -780,16 +780,16 @@ setReadOnly( CompactAdjacencyMatrix.prototype, 'outEdges', function outEdges( i setReadOnly( CompactAdjacencyMatrix.prototype, 'removeEdge', function removeEdge( i, j ) { var idx; if ( !isNonNegativeInteger( i ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a nonnegative integer. Value: `%s`.', i ) ); + throw new TypeError( format( '1S92d', i ) ); } if ( !isNonNegativeInteger( j ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', j ) ); + throw new TypeError( format( '1S93X', j ) ); } if ( i >= this._N ) { - throw new RangeError( format( 'invalid argument. First argument exceeds matrix dimensions. Value: `%u`.', i ) ); + throw new RangeError( format( '1S9Au', i ) ); } if ( j >= this._N ) { - throw new RangeError( format( 'invalid argument. Second argument exceeds matrix dimensions. Value: `%u`.', j ) ); + throw new RangeError( format( '1S9Av', j ) ); } // Resolve the `(i,j)` pair: idx = this._loc( i, j, [ 0, 0 ] ); diff --git a/package.json b/package.json index 5e29e63..130cd5a 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,7 @@ "@stdlib/boolean-ctor": "^0.2.1", "@stdlib/math-base-special-ceil": "^0.2.1", "@stdlib/math-base-special-floor": "^0.2.2", - "@stdlib/string-format": "^0.2.1", + "@stdlib/error-tools-fmtprodmsg": "^0.2.1", "@stdlib/symbol-iterator": "^0.2.1", "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.2.2", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.1",