From 2887a8505ca7d4d5ec1036300e926bb6e6a3952c Mon Sep 17 00:00:00 2001 From: Ajay Date: Sat, 13 Apr 2024 01:54:59 -0400 Subject: [PATCH] Improve logging and fix ip fetch error breaking skip segments --- src/routes/getBranding.ts | 2 ++ src/routes/getSkipSegments.ts | 15 ++++++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/routes/getBranding.ts b/src/routes/getBranding.ts index f6cfac2..b8e135d 100644 --- a/src/routes/getBranding.ts +++ b/src/routes/getBranding.ts @@ -223,6 +223,8 @@ async function shouldKeepSubmission(submissions: BrandingDBSubmission[], type: B return submitterIP.hashedIP === hashedIP; } catch (e) { // give up on shadow hide for now + Logger.error(`getBranding: Error while trying to find IP: ${e}`); + return false; } })); diff --git a/src/routes/getSkipSegments.ts b/src/routes/getSkipSegments.ts index 0ac2912..5e130ac 100644 --- a/src/routes/getSkipSegments.ts +++ b/src/routes/getSkipSegments.ts @@ -42,7 +42,10 @@ async function prepareCategorySegments(req: Request, videoID: VideoID, service: const fetchData = () => privateDB.prepare("all", 'SELECT "hashedIP" FROM "sponsorTimes" WHERE "videoID" = ? AND "timeSubmitted" = ? AND "service" = ?', [videoID, segment.timeSubmitted, service], { useReplica: true }) as Promise<{ hashedIP: HashedIP }[]>; try { - if (db.highLoad() || privateDB.highLoad()) throw new Error("High load, not handling shadowhide"); + if (db.highLoad() || privateDB.highLoad()) { + Logger.error("High load, not handling shadowhide"); + return false; + } cache.shadowHiddenSegmentIPs[videoID][segment.timeSubmitted] = promiseOrTimeout(QueryCacher.get(fetchData, shadowHiddenIPKey(videoID, segment.timeSubmitted, service)), 150); } catch (e) { @@ -51,7 +54,13 @@ async function prepareCategorySegments(req: Request, videoID: VideoID, service: } } - const ipList = await cache.shadowHiddenSegmentIPs[videoID][segment.timeSubmitted]; + let ipList = []; + try { + ipList = await cache.shadowHiddenSegmentIPs[videoID][segment.timeSubmitted]; + } catch (e) { + Logger.error(`skipSegments: Error while trying to find IP: ${e}`); + return false; + } if (ipList?.length > 0 && cache.userHashedIP === undefined) { cache.userHashedIP = await cache.userHashedIPPromise; @@ -186,7 +195,7 @@ async function getSegmentsByHash(req: Request, hashedVideoIDPrefix: VideoIDHash, return segments; } catch (err) /* istanbul ignore next */ { - Logger.error(err as string); + Logger.error(`get segments by hash error: ${err}`); return null; } }