From 6c178a4476d9b5b2b4d020ee1f07547995f05ca9 Mon Sep 17 00:00:00 2001 From: Manav Rathi Date: Tue, 2 Jul 2024 13:07:47 +0530 Subject: [PATCH] fix --- .../services/ml/machineLearningService.ts | 35 ++++++++++--------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/web/packages/new/photos/services/ml/machineLearningService.ts b/web/packages/new/photos/services/ml/machineLearningService.ts index 97e3abcd69..74287c1f7a 100644 --- a/web/packages/new/photos/services/ml/machineLearningService.ts +++ b/web/packages/new/photos/services/ml/machineLearningService.ts @@ -1,9 +1,9 @@ -import { EnteFile } from "@/new/photos/types/file"; +import type { EnteFile } from "@/new/photos/types/file"; import log from "@/next/log"; import { CustomError, parseUploadErrorCodes } from "@ente/shared/error"; import PQueue from "p-queue"; -import { syncWithLocalFilesAndGetFilesToIndex } from "services/ml/indexer"; -import { FaceIndexerWorker } from "services/ml/indexer.worker"; +import { syncWithLocalFilesAndGetFilesToIndex } from "./indexer"; +import { FaceIndexerWorker } from "./indexer.worker"; const batchSize = 200; @@ -12,10 +12,10 @@ class MLSyncContext { public userID: number; public userAgent: string; - public localFilesMap: Map; + public localFilesMap: Map | undefined; public outOfSyncFiles: EnteFile[]; public nSyncedFiles: number; - public error?: Error; + public error?: unknown; public syncQueue: PQueue; @@ -42,8 +42,8 @@ const getConcurrency = () => Math.max(2, Math.ceil(navigator.hardwareConcurrency / 2)); class MachineLearningService { - private localSyncContext: Promise; - private syncContext: Promise; + private localSyncContext: Promise | undefined; + private syncContext: Promise | undefined; public async sync( token: string, @@ -183,18 +183,21 @@ class MachineLearningService { syncContext.nSyncedFiles += 1; } catch (e) { let error = e; - if ("status" in error) { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + if ("status" in (error as any)) { const parsedMessage = parseUploadErrorCodes(error); error = parsedMessage; } - // TODO: throw errors not related to specific file - // sync job run should stop after these errors - // don't persist these errors against file, - // can include indexeddb/cache errors too - switch (error.message) { - case CustomError.SESSION_EXPIRED: - case CustomError.NETWORK_ERROR: - throw error; + if (error instanceof Error) { + // TODO: throw errors not related to specific file + // sync job run should stop after these errors + // don't persist these errors against file, + // can include indexeddb/cache errors too + switch (error.message) { + case CustomError.SESSION_EXPIRED: + case CustomError.NETWORK_ERROR: + throw error; + } } syncContext.nSyncedFiles += 1;