@@ -176,7 +176,10 @@ async function localSearch(
176176 searchArgs . room_id = roomId ;
177177 }
178178
179- const localResult = await eventIndex . search ( searchArgs ) ;
179+ const localResult = await eventIndex ! . search ( searchArgs ) ;
180+ if ( ! localResult ) {
181+ throw new Error ( "Local search failed" ) ;
182+ }
180183
181184 searchArgs . next_batch = localResult . next_batch ;
182185
@@ -225,7 +228,11 @@ async function localPagination(searchResult: ISeshatSearchResults): Promise<ISes
225228
226229 const searchArgs = searchResult . seshatQuery ;
227230
228- const localResult = await eventIndex . search ( searchArgs ) ;
231+ const localResult = await eventIndex ! . search ( searchArgs ) ;
232+ if ( ! localResult ) {
233+ throw new Error ( "Local search pagination failed" ) ;
234+ }
235+
229236 searchResult . seshatQuery . next_batch = localResult . next_batch ;
230237
231238 // We only need to restore the encryption state for the new results, so
@@ -477,7 +484,7 @@ function combineResponses(
477484 // Set the response next batch token to one of the tokens from the sources,
478485 // this makes sure that if we exhaust one of the sources we continue with
479486 // the other one.
480- if ( previousSearchResult . seshatQuery . next_batch ) {
487+ if ( previousSearchResult . seshatQuery ? .next_batch ) {
481488 response . next_batch = previousSearchResult . seshatQuery . next_batch ;
482489 } else if ( previousSearchResult . serverSideNextBatch ) {
483490 response . next_batch = previousSearchResult . serverSideNextBatch ;
@@ -535,13 +542,13 @@ async function combinedPagination(searchResult: ISeshatSearchResults): Promise<I
535542 const searchArgs = searchResult . seshatQuery ;
536543 const oldestEventFrom = searchResult . oldestEventFrom ;
537544
538- let localResult : IResultRoomEvents ;
539- let serverSideResult : ISearchResponse ;
545+ let localResult : IResultRoomEvents | undefined ;
546+ let serverSideResult : ISearchResponse | undefined ;
540547
541548 // Fetch events from the local index if we have a token for it and if it's
542549 // the local indexes turn or the server has exhausted its results.
543- if ( searchArgs . next_batch && ( ! searchResult . serverSideNextBatch || oldestEventFrom === "server" ) ) {
544- localResult = await eventIndex . search ( searchArgs ) ;
550+ if ( searchArgs ? .next_batch && ( ! searchResult . serverSideNextBatch || oldestEventFrom === "server" ) ) {
551+ localResult = await eventIndex ! . search ( searchArgs ) ;
545552 }
546553
547554 // Fetch events from the server if we have a token for it and if it's the
@@ -551,7 +558,7 @@ async function combinedPagination(searchResult: ISeshatSearchResults): Promise<I
551558 serverSideResult = await client . search ( body ) ;
552559 }
553560
554- let serverEvents : IResultRoomEvents ;
561+ let serverEvents : IResultRoomEvents | undefined ;
555562
556563 if ( serverSideResult ) {
557564 serverEvents = serverSideResult . search_categories . room_events ;
0 commit comments