@@ -144,7 +144,7 @@ function initSearch(rawSearchIndex) {
144
144
function itemTypeFromName ( typename ) {
145
145
const index = itemTypes . findIndex ( i => i === typename ) ;
146
146
if ( index < 0 ) {
147
- throw new Error ( "Unknown type filter `" + typename + "`" ) ;
147
+ throw [ "Unknown type filter " , typename ] ;
148
148
}
149
149
return index ;
150
150
}
@@ -164,21 +164,21 @@ function initSearch(rawSearchIndex) {
164
164
*/
165
165
function getStringElem ( query , parserState , isInGenerics ) {
166
166
if ( isInGenerics ) {
167
- throw new Error ( "`\"` cannot be used in generics") ;
167
+ throw [ "Unexpected " , "\"" , " in generics"] ;
168
168
} else if ( query . literalSearch ) {
169
- throw new Error ( "Cannot have more than one literal search element" ) ;
169
+ throw [ "Cannot have more than one literal search element" ] ;
170
170
} else if ( parserState . totalElems - parserState . genericsElems > 0 ) {
171
- throw new Error ( "Cannot use literal search when there is more than one element" ) ;
171
+ throw [ "Cannot use literal search when there is more than one element" ] ;
172
172
}
173
173
parserState . pos += 1 ;
174
174
const start = parserState . pos ;
175
175
const end = getIdentEndPosition ( parserState ) ;
176
176
if ( parserState . pos >= parserState . length ) {
177
- throw new Error ( "Unclosed `\"`" ) ;
177
+ throw [ "Unclosed " , "\"" ] ;
178
178
} else if ( parserState . userQuery [ end ] !== "\"" ) {
179
- throw new Error ( ` Unexpected \` ${ parserState . userQuery [ end ] } \` in a string element` ) ;
179
+ throw [ " Unexpected " , parserState . userQuery [ end ] , " in a string element" ] ;
180
180
} else if ( start === end ) {
181
- throw new Error ( "Cannot have empty string element" ) ;
181
+ throw [ "Cannot have empty string element" ] ;
182
182
}
183
183
// To skip the quote at the end.
184
184
parserState . pos += 1 ;
@@ -257,7 +257,7 @@ function initSearch(rawSearchIndex) {
257
257
return ;
258
258
}
259
259
if ( query . literalSearch && parserState . totalElems - parserState . genericsElems > 0 ) {
260
- throw new Error ( "You cannot have more than one element if you use quotes" ) ;
260
+ throw [ "You cannot have more than one element if you use quotes" ] ;
261
261
}
262
262
const pathSegments = name . split ( "::" ) ;
263
263
if ( pathSegments . length > 1 ) {
@@ -266,17 +266,17 @@ function initSearch(rawSearchIndex) {
266
266
267
267
if ( pathSegment . length === 0 ) {
268
268
if ( i === 0 ) {
269
- throw new Error ( "Paths cannot start with `::`" ) ;
269
+ throw [ "Paths cannot start with " , "::" ] ;
270
270
} else if ( i + 1 === len ) {
271
- throw new Error ( "Paths cannot end with `::`" ) ;
271
+ throw [ "Paths cannot end with " , "::" ] ;
272
272
}
273
- throw new Error ( "Unexpected ` ::::`" ) ;
273
+ throw [ "Unexpected " , " ::::" ] ;
274
274
}
275
275
}
276
276
}
277
277
// In case we only have something like `<p>`, there is no name.
278
278
if ( pathSegments . length === 0 || ( pathSegments . length === 1 && pathSegments [ 0 ] === "" ) ) {
279
- throw new Error ( "Found generics without a path" ) ;
279
+ throw [ "Found generics without a path" ] ;
280
280
}
281
281
parserState . totalElems += 1 ;
282
282
if ( isInGenerics ) {
@@ -308,15 +308,15 @@ function initSearch(rawSearchIndex) {
308
308
if ( ! isIdentCharacter ( c ) ) {
309
309
if ( c === "!" ) {
310
310
if ( foundExclamation !== - 1 ) {
311
- throw new Error ( "Cannot have more than one `!` in an ident" ) ;
311
+ throw [ "Cannot have more than one " , "!" , " in an ident"] ;
312
312
} else if ( parserState . pos + 1 < parserState . length &&
313
313
isIdentCharacter ( parserState . userQuery [ parserState . pos + 1 ] )
314
314
) {
315
- throw new Error ( "`!` can only be at the end of an ident") ;
315
+ throw [ "Unexpected " , "!" , ": it can only be at the end of an ident"] ;
316
316
}
317
317
foundExclamation = parserState . pos ;
318
318
} else if ( isErrorCharacter ( c ) ) {
319
- throw new Error ( ` Unexpected \` ${ c } \`` ) ;
319
+ throw [ " Unexpected " , c ] ;
320
320
} else if (
321
321
isStopCharacter ( c ) ||
322
322
isSpecialStartCharacter ( c ) ||
@@ -329,7 +329,7 @@ function initSearch(rawSearchIndex) {
329
329
}
330
330
if ( foundExclamation !== - 1 ) {
331
331
if ( start <= ( end - 2 ) ) {
332
- throw new Error ( "Cannot have associated items in macros" ) ;
332
+ throw [ "Cannot have associated items in macros" ] ;
333
333
} else {
334
334
// if start == end - 1, we got the never type
335
335
// while the never type has no associated macros, we still
@@ -340,7 +340,7 @@ function initSearch(rawSearchIndex) {
340
340
// Skip current ":".
341
341
parserState . pos += 1 ;
342
342
} else {
343
- throw new Error ( ` Unexpected \` ${ c } \`` ) ;
343
+ throw [ " Unexpected " , c ] ;
344
344
}
345
345
}
346
346
parserState . pos += 1 ;
@@ -351,8 +351,13 @@ function initSearch(rawSearchIndex) {
351
351
if ( parserState . typeFilter === null ) {
352
352
parserState . typeFilter = "macro" ;
353
353
} else if ( parserState . typeFilter !== "macro" ) {
354
- throw new Error ( "Invalid search type: macro `!` and " +
355
- `\`${ parserState . typeFilter } \` both specified` ) ;
354
+ throw [
355
+ "Invalid search type: macro " ,
356
+ "!" ,
357
+ " and " ,
358
+ parserState . typeFilter ,
359
+ " both specified" ,
360
+ ] ;
356
361
}
357
362
end = foundExclamation ;
358
363
}
@@ -382,9 +387,9 @@ function initSearch(rawSearchIndex) {
382
387
parserState . userQuery [ parserState . pos ] === "<"
383
388
) {
384
389
if ( isInGenerics ) {
385
- throw new Error ( "Unexpected `<` after `<`" ) ;
390
+ throw [ "Unexpected " , "<" , " after " , "<" ] ;
386
391
} else if ( start >= end ) {
387
- throw new Error ( "Found generics without a path" ) ;
392
+ throw [ "Found generics without a path" ] ;
388
393
}
389
394
parserState . pos += 1 ;
390
395
getItemsBefore ( query , parserState , generics , ">" ) ;
@@ -428,21 +433,39 @@ function initSearch(rawSearchIndex) {
428
433
foundStopChar = true ;
429
434
continue ;
430
435
} else if ( c === ":" && isPathStart ( parserState ) ) {
431
- throw new Error ( "Unexpected `::` : paths cannot start with `::`" ) ;
436
+ throw [ "Unexpected " , "::" , " : paths cannot start with " , "::" ] ;
432
437
} else if ( c === ":" || isEndCharacter ( c ) ) {
433
438
let extra = "" ;
434
439
if ( endChar === ">" ) {
435
- extra = "`<` " ;
440
+ extra = "< " ;
436
441
} else if ( endChar === "" ) {
437
- extra = "`->`" ;
442
+ extra = "->" ;
443
+ } else {
444
+ extra = endChar ;
438
445
}
439
- throw new Error ( "Unexpected `" + c + "` after " + extra ) ;
446
+ throw [ "Unexpected " , c , " after ", extra ] ;
440
447
}
441
448
if ( ! foundStopChar ) {
442
449
if ( endChar !== "" ) {
443
- throw new Error ( `Expected \`,\`, \` \` or \`${ endChar } \`, found \`${ c } \`` ) ;
450
+ throw [
451
+ "Expected " ,
452
+ "," , // comma
453
+ ", " ,
454
+ " " , // whitespace
455
+ " or " ,
456
+ endChar ,
457
+ ", found " ,
458
+ c ,
459
+ ] ;
444
460
}
445
- throw new Error ( `Expected \`,\` or \` \`, found \`${ c } \`` ) ;
461
+ throw [
462
+ "Expected " ,
463
+ "," , // comma
464
+ " or " ,
465
+ " " , // whitespace
466
+ ", found " ,
467
+ c ,
468
+ ] ;
446
469
}
447
470
const posBefore = parserState . pos ;
448
471
getNextElem ( query , parserState , elems , endChar === ">" ) ;
@@ -470,7 +493,7 @@ function initSearch(rawSearchIndex) {
470
493
471
494
for ( let pos = 0 ; pos < parserState . pos ; ++ pos ) {
472
495
if ( ! isIdentCharacter ( query [ pos ] ) && ! isWhitespaceCharacter ( query [ pos ] ) ) {
473
- throw new Error ( ` Unexpected \` ${ query [ pos ] } \` in type filter` ) ;
496
+ throw [ " Unexpected " , query [ pos ] , " in type filter" ] ;
474
497
}
475
498
}
476
499
}
@@ -496,19 +519,19 @@ function initSearch(rawSearchIndex) {
496
519
if ( isReturnArrow ( parserState ) ) {
497
520
break ;
498
521
}
499
- throw new Error ( ` Unexpected \` ${ c } \` (did you mean \`->\`?)` ) ;
522
+ throw [ " Unexpected " , c , " (did you mean " , "->" , "?)" ] ;
500
523
}
501
- throw new Error ( ` Unexpected \` ${ c } \`` ) ;
524
+ throw [ " Unexpected " , c ] ;
502
525
} else if ( c === ":" && ! isPathStart ( parserState ) ) {
503
526
if ( parserState . typeFilter !== null ) {
504
- throw new Error ( "Unexpected `:`" ) ;
527
+ throw [ "Unexpected " , ":" ] ;
505
528
}
506
529
if ( query . elems . length === 0 ) {
507
- throw new Error ( "Expected type filter before `:`" ) ;
530
+ throw [ "Expected type filter before " , ":" ] ;
508
531
} else if ( query . elems . length !== 1 || parserState . totalElems !== 1 ) {
509
- throw new Error ( "Unexpected `:`" ) ;
532
+ throw [ "Unexpected " , ":" ] ;
510
533
} else if ( query . literalSearch ) {
511
- throw new Error ( "You cannot use quotes on type filter" ) ;
534
+ throw [ "You cannot use quotes on type filter" ] ;
512
535
}
513
536
checkExtraTypeFilterCharacters ( parserState ) ;
514
537
// The type filter doesn't count as an element since it's a modifier.
@@ -521,9 +544,29 @@ function initSearch(rawSearchIndex) {
521
544
}
522
545
if ( ! foundStopChar ) {
523
546
if ( parserState . typeFilter !== null ) {
524
- throw new Error ( `Expected \`,\`, \` \` or \`->\`, found \`${ c } \`` ) ;
547
+ throw [
548
+ "Expected " ,
549
+ "," , // comma
550
+ ", " ,
551
+ " " , // whitespace
552
+ " or " ,
553
+ "->" , // arrow
554
+ ", found " ,
555
+ c ,
556
+ ] ;
525
557
}
526
- throw new Error ( `Expected \`,\`, \` \`, \`:\` or \`->\`, found \`${ c } \`` ) ;
558
+ throw [
559
+ "Expected " ,
560
+ "," , // comma
561
+ ", " ,
562
+ " " , // whitespace
563
+ ", " ,
564
+ ":" , // colon
565
+ " or " ,
566
+ "->" , // arrow
567
+ ", found " ,
568
+ c ,
569
+ ] ;
527
570
}
528
571
const before = query . elems . length ;
529
572
getNextElem ( query , parserState , query . elems , false ) ;
@@ -540,7 +583,7 @@ function initSearch(rawSearchIndex) {
540
583
getItemsBefore ( query , parserState , query . returned , "" ) ;
541
584
// Nothing can come afterward!
542
585
if ( query . returned . length === 0 ) {
543
- throw new Error ( "Expected at least one item after `->`" ) ;
586
+ throw [ "Expected at least one item after " , "->" ] ;
544
587
}
545
588
break ;
546
589
} else {
@@ -694,7 +737,7 @@ function initSearch(rawSearchIndex) {
694
737
}
695
738
} catch ( err ) {
696
739
query = newParsedQuery ( userQuery ) ;
697
- query . error = err . message ;
740
+ query . error = err ;
698
741
query . typeFilter = - 1 ;
699
742
return query ;
700
743
}
@@ -1760,7 +1803,16 @@ function initSearch(rawSearchIndex) {
1760
1803
1761
1804
let output = `<h1 class="search-results-title">Results${ crates } </h1>` ;
1762
1805
if ( results . query . error !== null ) {
1763
- output += `<h3>Query parser error: "${ results . query . error } ".</h3>` ;
1806
+ const error = results . query . error ;
1807
+ error . forEach ( ( value , index ) => {
1808
+ value = value . split ( "<" ) . join ( "<" ) . split ( ">" ) . join ( ">" ) ;
1809
+ if ( index % 2 !== 0 ) {
1810
+ error [ index ] = `<code>${ value } </code>` ;
1811
+ } else {
1812
+ error [ index ] = value ;
1813
+ }
1814
+ } ) ;
1815
+ output += `<h3 class="error">Query parser error: "${ error . join ( "" ) } ".</h3>` ;
1764
1816
output += "<div id=\"search-tabs\">" +
1765
1817
makeTabHeader ( 0 , "In Names" , ret_others [ 1 ] ) +
1766
1818
"</div>" ;
0 commit comments