From 6a6d0db810201021ee173465fa31287d0d1381a3 Mon Sep 17 00:00:00 2001 From: Chris Voon Date: Tue, 19 May 2026 22:15:17 -0700 Subject: [PATCH 1/2] Warn instead of crashing when encountering unknown enum values with scraper --- prisma/mappers.ts | 12 ++++++++---- prisma/scraper.ts | 7 ++----- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/prisma/mappers.ts b/prisma/mappers.ts index 7b1ecc2..85c2bf1 100644 --- a/prisma/mappers.ts +++ b/prisma/mappers.ts @@ -32,7 +32,8 @@ export function mapCampusArea(area: RawCampusArea): CampusArea { case 'South': return CampusArea.SOUTH; default: - throw new Error(`Unknown campus area: ${area.descrshort}`); + console.warn(`Unknown campus area: ${area.descrshort}, defaulting to CENTRAL`); + return CampusArea.CENTRAL; } } @@ -53,7 +54,8 @@ export function mapPaymentMethod(method: RawPayMethod): PaymentMethod { case 'Free': return PaymentMethod.FREE; default: - throw new Error(`Unknown payment method: ${method.descrshort}`); + console.warn(`Unknown payment method: ${method.descrshort}, defaulting to CARD`); + return PaymentMethod.CARD; } } @@ -75,7 +77,8 @@ export function mapEateryType(type: RawEateryType): EateryType { case 'General': return EateryType.GENERAL; default: - throw new Error(`Unknown eatery type: ${type.descr}`); + console.warn(`Unknown eatery type: ${type.descr}, defaulting to GENERAL`); + return EateryType.GENERAL; } } @@ -107,7 +110,8 @@ export function mapEventType(eventDescription: string): EventType { case 'Free Food': return EventType.GENERAL; default: - throw new Error(`Unknown event type: ${eventDescription}`); + console.warn(`Unknown event type: ${eventDescription}, defaulting to GENERAL`); + return EventType.GENERAL; } } diff --git a/prisma/scraper.ts b/prisma/scraper.ts index 300b281..900627c 100644 --- a/prisma/scraper.ts +++ b/prisma/scraper.ts @@ -385,11 +385,8 @@ async function transformEateriesConcurrently( } if (errors.length > 0) { - const errorMessages = errors - .map((e) => `Eatery "${e.eatery.name}": ${e.error}`) - .join('\n'); - throw new Error( - `Failed to transform ${errors.length} eatery(ies):\n${errorMessages}`, + console.warn( + `Skipped ${errors.length} API eatery(ies) due to transform errors`, ); } From f20ff0966929c256934e61386cd0472eaf7b054d Mon Sep 17 00:00:00 2001 From: Chris Voon Date: Wed, 20 May 2026 00:02:03 -0700 Subject: [PATCH 2/2] Crash if over 50% of eateries fail to transform --- prisma/scraper.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/prisma/scraper.ts b/prisma/scraper.ts index 900627c..1de60b8 100644 --- a/prisma/scraper.ts +++ b/prisma/scraper.ts @@ -385,6 +385,12 @@ async function transformEateriesConcurrently( } if (errors.length > 0) { + const failureRate = errors.length / rawEateries.length; + if (failureRate >= 0.5) { + throw new Error( + `Aborting: ${errors.length}/${rawEateries.length} API eateries failed to transform (${Math.round(failureRate * 100)}%)`, + ); + } console.warn( `Skipped ${errors.length} API eatery(ies) due to transform errors`, );