@@ -144,7 +144,7 @@ function initSearch(rawSearchIndex) {
144144 function itemTypeFromName ( typename ) {
145145 const index = itemTypes . findIndex ( i => i === typename ) ;
146146 if ( index < 0 ) {
147- throw new Error ( "Unknown type filter `" + typename + "`" ) ;
147+ throw [ "Unknown type filter " , typename ] ;
148148 }
149149 return index ;
150150 }
@@ -164,21 +164,21 @@ function initSearch(rawSearchIndex) {
164164 */
165165 function getStringElem ( query , parserState , isInGenerics ) {
166166 if ( isInGenerics ) {
167- throw new Error ( "`\"` cannot be used in generics") ;
167+ throw [ "Unexpected " , "\"" , " in generics"] ;
168168 } 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" ] ;
170170 } 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" ] ;
172172 }
173173 parserState . pos += 1 ;
174174 const start = parserState . pos ;
175175 const end = getIdentEndPosition ( parserState ) ;
176176 if ( parserState . pos >= parserState . length ) {
177- throw new Error ( "Unclosed `\"`" ) ;
177+ throw [ "Unclosed " , "\"" ] ;
178178 } 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" ] ;
180180 } else if ( start === end ) {
181- throw new Error ( "Cannot have empty string element" ) ;
181+ throw [ "Cannot have empty string element" ] ;
182182 }
183183 // To skip the quote at the end.
184184 parserState . pos += 1 ;
@@ -257,7 +257,7 @@ function initSearch(rawSearchIndex) {
257257 return ;
258258 }
259259 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" ] ;
261261 }
262262 const pathSegments = name . split ( "::" ) ;
263263 if ( pathSegments . length > 1 ) {
@@ -266,17 +266,17 @@ function initSearch(rawSearchIndex) {
266266
267267 if ( pathSegment . length === 0 ) {
268268 if ( i === 0 ) {
269- throw new Error ( "Paths cannot start with `::`" ) ;
269+ throw [ "Paths cannot start with " , "::" ] ;
270270 } else if ( i + 1 === len ) {
271- throw new Error ( "Paths cannot end with `::`" ) ;
271+ throw [ "Paths cannot end with " , "::" ] ;
272272 }
273- throw new Error ( "Unexpected ` ::::`" ) ;
273+ throw [ "Unexpected " , " ::::" ] ;
274274 }
275275 }
276276 }
277277 // In case we only have something like `<p>`, there is no name.
278278 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" ] ;
280280 }
281281 parserState . totalElems += 1 ;
282282 if ( isInGenerics ) {
@@ -308,15 +308,15 @@ function initSearch(rawSearchIndex) {
308308 if ( ! isIdentCharacter ( c ) ) {
309309 if ( c === "!" ) {
310310 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"] ;
312312 } else if ( parserState . pos + 1 < parserState . length &&
313313 isIdentCharacter ( parserState . userQuery [ parserState . pos + 1 ] )
314314 ) {
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"] ;
316316 }
317317 foundExclamation = parserState . pos ;
318318 } else if ( isErrorCharacter ( c ) ) {
319- throw new Error ( ` Unexpected \` ${ c } \`` ) ;
319+ throw [ " Unexpected " , c ] ;
320320 } else if (
321321 isStopCharacter ( c ) ||
322322 isSpecialStartCharacter ( c ) ||
@@ -329,7 +329,7 @@ function initSearch(rawSearchIndex) {
329329 }
330330 if ( foundExclamation !== - 1 ) {
331331 if ( start <= ( end - 2 ) ) {
332- throw new Error ( "Cannot have associated items in macros" ) ;
332+ throw [ "Cannot have associated items in macros" ] ;
333333 } else {
334334 // if start == end - 1, we got the never type
335335 // while the never type has no associated macros, we still
@@ -340,7 +340,7 @@ function initSearch(rawSearchIndex) {
340340 // Skip current ":".
341341 parserState . pos += 1 ;
342342 } else {
343- throw new Error ( ` Unexpected \` ${ c } \`` ) ;
343+ throw [ " Unexpected " , c ] ;
344344 }
345345 }
346346 parserState . pos += 1 ;
@@ -351,8 +351,13 @@ function initSearch(rawSearchIndex) {
351351 if ( parserState . typeFilter === null ) {
352352 parserState . typeFilter = "macro" ;
353353 } 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+ ] ;
356361 }
357362 end = foundExclamation ;
358363 }
@@ -382,9 +387,9 @@ function initSearch(rawSearchIndex) {
382387 parserState . userQuery [ parserState . pos ] === "<"
383388 ) {
384389 if ( isInGenerics ) {
385- throw new Error ( "Unexpected `<` after `<`" ) ;
390+ throw [ "Unexpected " , "<" , " after " , "<" ] ;
386391 } else if ( start >= end ) {
387- throw new Error ( "Found generics without a path" ) ;
392+ throw [ "Found generics without a path" ] ;
388393 }
389394 parserState . pos += 1 ;
390395 getItemsBefore ( query , parserState , generics , ">" ) ;
@@ -428,21 +433,39 @@ function initSearch(rawSearchIndex) {
428433 foundStopChar = true ;
429434 continue ;
430435 } else if ( c === ":" && isPathStart ( parserState ) ) {
431- throw new Error ( "Unexpected `::` : paths cannot start with `::`" ) ;
436+ throw [ "Unexpected " , "::" , " : paths cannot start with " , "::" ] ;
432437 } else if ( c === ":" || isEndCharacter ( c ) ) {
433438 let extra = "" ;
434439 if ( endChar === ">" ) {
435- extra = "`<` " ;
440+ extra = "< " ;
436441 } else if ( endChar === "" ) {
437- extra = "`->`" ;
442+ extra = "->" ;
443+ } else {
444+ extra = endChar ;
438445 }
439- throw new Error ( "Unexpected `" + c + "` after " + extra ) ;
446+ throw [ "Unexpected " , c , " after ", extra ] ;
440447 }
441448 if ( ! foundStopChar ) {
442449 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+ ] ;
444460 }
445- throw new Error ( `Expected \`,\` or \` \`, found \`${ c } \`` ) ;
461+ throw [
462+ "Expected " ,
463+ "," , // comma
464+ " or " ,
465+ " " , // whitespace
466+ ", found " ,
467+ c ,
468+ ] ;
446469 }
447470 const posBefore = parserState . pos ;
448471 getNextElem ( query , parserState , elems , endChar === ">" ) ;
@@ -470,7 +493,7 @@ function initSearch(rawSearchIndex) {
470493
471494 for ( let pos = 0 ; pos < parserState . pos ; ++ pos ) {
472495 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" ] ;
474497 }
475498 }
476499 }
@@ -496,19 +519,19 @@ function initSearch(rawSearchIndex) {
496519 if ( isReturnArrow ( parserState ) ) {
497520 break ;
498521 }
499- throw new Error ( ` Unexpected \` ${ c } \` (did you mean \`->\`?)` ) ;
522+ throw [ " Unexpected " , c , " (did you mean " , "->" , "?)" ] ;
500523 }
501- throw new Error ( ` Unexpected \` ${ c } \`` ) ;
524+ throw [ " Unexpected " , c ] ;
502525 } else if ( c === ":" && ! isPathStart ( parserState ) ) {
503526 if ( parserState . typeFilter !== null ) {
504- throw new Error ( "Unexpected `:`" ) ;
527+ throw [ "Unexpected " , ":" ] ;
505528 }
506529 if ( query . elems . length === 0 ) {
507- throw new Error ( "Expected type filter before `:`" ) ;
530+ throw [ "Expected type filter before " , ":" ] ;
508531 } else if ( query . elems . length !== 1 || parserState . totalElems !== 1 ) {
509- throw new Error ( "Unexpected `:`" ) ;
532+ throw [ "Unexpected " , ":" ] ;
510533 } else if ( query . literalSearch ) {
511- throw new Error ( "You cannot use quotes on type filter" ) ;
534+ throw [ "You cannot use quotes on type filter" ] ;
512535 }
513536 checkExtraTypeFilterCharacters ( parserState ) ;
514537 // The type filter doesn't count as an element since it's a modifier.
@@ -521,9 +544,29 @@ function initSearch(rawSearchIndex) {
521544 }
522545 if ( ! foundStopChar ) {
523546 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+ ] ;
525557 }
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+ ] ;
527570 }
528571 const before = query . elems . length ;
529572 getNextElem ( query , parserState , query . elems , false ) ;
@@ -540,7 +583,7 @@ function initSearch(rawSearchIndex) {
540583 getItemsBefore ( query , parserState , query . returned , "" ) ;
541584 // Nothing can come afterward!
542585 if ( query . returned . length === 0 ) {
543- throw new Error ( "Expected at least one item after `->`" ) ;
586+ throw [ "Expected at least one item after " , "->" ] ;
544587 }
545588 break ;
546589 } else {
@@ -694,7 +737,7 @@ function initSearch(rawSearchIndex) {
694737 }
695738 } catch ( err ) {
696739 query = newParsedQuery ( userQuery ) ;
697- query . error = err . message ;
740+ query . error = err ;
698741 query . typeFilter = - 1 ;
699742 return query ;
700743 }
@@ -1760,7 +1803,16 @@ function initSearch(rawSearchIndex) {
17601803
17611804 let output = `<h1 class="search-results-title">Results${ crates } </h1>` ;
17621805 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>` ;
17641816 output += "<div id=\"search-tabs\">" +
17651817 makeTabHeader ( 0 , "In Names" , ret_others [ 1 ] ) +
17661818 "</div>" ;
0 commit comments