diff --git a/src/background-script/setup.ts b/src/background-script/setup.ts index e22a795a38..9f6fd6aea7 100644 --- a/src/background-script/setup.ts +++ b/src/background-script/setup.ts @@ -61,8 +61,8 @@ import ActivityIndicatorBackground from 'src/activity-indicator/background' import SummarizeBackground from 'src/summarization-llm/background' import ActivityStreamsBackground from 'src/activity-streams/background' import { SyncSettingsBackground } from 'src/sync-settings/background' -import { AuthServices, Services } from 'src/services/types' -import { captureException } from 'src/util/raven' +import type { AuthServices, Services } from 'src/services/types' +import type { captureException } from 'src/util/raven' import { PDFBackground } from 'src/pdf/background' // import { FirebaseUserMessageService } from '@worldbrain/memex-common/lib/user-messages/service/firebase' // import { UserMessageService } from '@worldbrain/memex-common/lib/user-messages/service/types' @@ -285,9 +285,10 @@ export function createBackgroundModules(options: { }) const search = new SearchBackground({ - storageManager, pages, analyticsBG, + storageManager, + captureException: options.captureException, }) const tags = new TagsBackground({ diff --git a/src/search/background/index.ts b/src/search/background/index.ts index 918b50cb26..1b10b5629d 100644 --- a/src/search/background/index.ts +++ b/src/search/background/index.ts @@ -61,6 +61,7 @@ import { PDF_PAGE_URL_PREFIX } from '@worldbrain/memex-common/lib/page-indexing/ import { EVENT_PROVIDER_URLS } from '@worldbrain/memex-common/lib/constants' import { TWITTER_URLS } from '@worldbrain/memex-common/lib/twitter-integration/constants' import { normalizeUrl } from '@worldbrain/memex-common/lib/url-utils/normalize' +import type { captureException } from 'src/util/raven' export default class SearchBackground { storage: SearchStorage @@ -103,6 +104,7 @@ export default class SearchBackground { storageManager: Storex pages: PageIndexingBackground analyticsBG: AnalyticsCoreInterface + captureException: typeof captureException }, ) { this.storage = new SearchStorage({ @@ -520,11 +522,30 @@ export default class SearchBackground { .table('annotations') .bulkGet([...validAnnotIds]) + let anyNonExistentAnnot = false // Add in all the annotations to the results const annotsByPage = groupBy( - [...autoSharedAnnots, ...selectivelySharedAnnots], + [...autoSharedAnnots, ...selectivelySharedAnnots] + // Sometimes annotListEntries can refer to annotations that were deleted due to old buggy delete logic + .filter((annot) => { + let annotExists = annot != null + if (annotExists) { + anyNonExistentAnnot = true + } + return annotExists + }), (a) => a.pageUrl, ) + + // Log it in sentry so we get an idea of how many times users have this case + if (anyNonExistentAnnot) { + this.options.captureException( + new Error( + `OwnError: Encountered annotListEntry referencing non-existent annotation`, + ), + ) + } + for (const [pageId, annots] of Object.entries(annotsByPage)) { const descOrderedAnnots = annots.sort( (a, b) => b.lastEdited.valueOf() - a.lastEdited.valueOf(),