File tree Expand file tree Collapse file tree 2 files changed +37
-3
lines changed Expand file tree Collapse file tree 2 files changed +37
-3
lines changed Original file line number Diff line number Diff line change 140
140
var TYPE_NULL = 7 ;
141
141
var TYPE_ARRAY_NUMBER = 8 ;
142
142
var TYPE_ARRAY_STRING = 9 ;
143
+ var TYPE_NAME_TABLE = {
144
+ 0 : 'number' ,
145
+ 1 : 'any' ,
146
+ 2 : 'string' ,
147
+ 3 : 'array' ,
148
+ 4 : 'object' ,
149
+ 5 : 'boolean' ,
150
+ 6 : 'expression' ,
151
+ 7 : 'null' ,
152
+ 8 : 'Array<number>' ,
153
+ 9 : 'Array<string>'
154
+ } ;
143
155
144
156
var TOK_EOF = "EOF" ;
145
157
var TOK_UNQUOTEDIDENTIFIER = "UnquotedIdentifier" ;
1237
1249
}
1238
1250
}
1239
1251
if ( ! typeMatched ) {
1252
+ var expected = currentSpec
1253
+ . map ( function ( typeIdentifier ) {
1254
+ return TYPE_NAME_TABLE [ typeIdentifier ] ;
1255
+ } )
1256
+ . join ( ',' ) ;
1240
1257
throw new Error ( "TypeError: " + name + "() " +
1241
1258
"expected argument " + ( i + 1 ) +
1242
- " to be type " + currentSpec +
1243
- " but received type " + actualType +
1244
- " instead." ) ;
1259
+ " to be type " + expected +
1260
+ " but received type " +
1261
+ TYPE_NAME_TABLE [ actualType ] + " instead." ) ;
1245
1262
}
1246
1263
}
1247
1264
} ,
Original file line number Diff line number Diff line change @@ -160,6 +160,7 @@ describe('tokenize', function() {
160
160
]
161
161
) ;
162
162
} ) ;
163
+
163
164
} ) ;
164
165
165
166
@@ -215,3 +216,19 @@ describe('strictDeepEqual', function() {
215
216
{ a : { b : [ 1 , 4 ] } } ) , false ) ;
216
217
} ) ;
217
218
} ) ;
219
+
220
+ describe ( 'search' , function ( ) {
221
+ it (
222
+ 'should throw a readable error when invalid arguments are provided to a function' ,
223
+ function ( ) {
224
+ try {
225
+ jmespath . search ( [ ] , 'length(`null`)' ) ;
226
+ } catch ( e ) {
227
+ assert ( e . message . search (
228
+ 'expected argument 1 to be type string,array,object'
229
+ ) , e . message ) ;
230
+ assert ( e . message . search ( 'received type null' ) , e . message ) ;
231
+ }
232
+ }
233
+ ) ;
234
+ } ) ;
You can’t perform that action at this time.
0 commit comments