From ef61f5f543bfeaa9821fd086d0b2a971334f2027 Mon Sep 17 00:00:00 2001 From: Jonathan Poltak Samosir Date: Mon, 17 Jun 2019 20:27:52 +0700 Subject: [PATCH] Stop 'Page has no searchable content' error notif - this error should never show a notif; it's not related to users - addresses #838 --- .../background/log-page-visit.ts | 19 ++++++++++++++----- src/search/index.ts | 2 ++ src/search/pipeline.ts | 6 +++++- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/src/activity-logger/background/log-page-visit.ts b/src/activity-logger/background/log-page-visit.ts index f59eb0d316..f1d1eeae7f 100644 --- a/src/activity-logger/background/log-page-visit.ts +++ b/src/activity-logger/background/log-page-visit.ts @@ -110,7 +110,10 @@ export default class PageVisitLogger { }) } catch (err) { this._tabManager.clearScheduledLog(tab.id) - throw err + + if (!(err instanceof searchIndex.PipelineError)) { + throw err + } } } @@ -144,9 +147,15 @@ export default class PageVisitLogger { return } - await this._createPage({ - pageDoc, - visits: [internalTabState.visitTime], - }) + try { + await this._createPage({ + pageDoc, + visits: [internalTabState.visitTime], + }) + } catch (err) { + if (!(err instanceof searchIndex.PipelineError)) { + throw err + } + } } } diff --git a/src/search/index.ts b/src/search/index.ts index 41b8ee54fd..2b709a5ea8 100644 --- a/src/search/index.ts +++ b/src/search/index.ts @@ -8,3 +8,5 @@ export * from './on-demand-indexing' export * from './types' export * from './models' export { default as getDb } from './get-db' + +export { PipelineError } from './pipeline' diff --git a/src/search/pipeline.ts b/src/search/pipeline.ts index 1b1cf7630d..563d96c014 100644 --- a/src/search/pipeline.ts +++ b/src/search/pipeline.ts @@ -3,6 +3,8 @@ import transformPageText from '../util/transform-page-text' import { DEFAULT_TERM_SEPARATOR, extractContent } from './util' import { PipelineReq, PipelineRes } from './types' +export class PipelineError extends Error {} + /** * Derived from answer in: https://stackoverflow.com/a/23945027 */ @@ -105,7 +107,9 @@ export default function pipeline({ rejectNoContent && (content == null || !content.fullText || !content.fullText.length) ) { - return Promise.reject(new Error('Page has no searchable content')) + return Promise.reject( + new PipelineError('Page has no searchable content'), + ) } // Extract all terms out of processed content