From 02b933d893979d7117620502d82a313a7796a77e Mon Sep 17 00:00:00 2001 From: Marco Gallegos Date: Sun, 18 Jan 2026 09:54:51 -0600 Subject: [PATCH] Fix JSON parsing error in Google Calendar initialization - Add try-catch for JSON.parse with better error handling - Validate credentials structure before use - Add detailed error logging for debugging - Prevent build failure from invalid GOOGLE_SERVICE_ACCOUNT_JSON Fixes SyntaxError during Next.js build process --- lib/google-calendar.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/google-calendar.ts b/lib/google-calendar.ts index 32e8cfb..7073fd1 100644 --- a/lib/google-calendar.ts +++ b/lib/google-calendar.ts @@ -46,7 +46,19 @@ class GoogleCalendarService { return; } - const credentials = JSON.parse(serviceAccountJson) as ServiceAccountConfig; + let credentials: ServiceAccountConfig; + + try { + credentials = JSON.parse(serviceAccountJson) as ServiceAccountConfig; + } catch (jsonError) { + console.error('GoogleCalendar: Failed to parse GOOGLE_SERVICE_ACCOUNT_JSON', jsonError); + console.error('GoogleCalendar: Service account JSON value:', serviceAccountJson); + throw new Error('Invalid GOOGLE_SERVICE_ACCOUNT_JSON format. Please check environment variable.'); + } + + if (!credentials.type || !credentials.project_id || !credentials.private_key) { + throw new Error('Invalid GOOGLE_SERVICE_ACCOUNT_JSON: Missing required fields'); + } const auth = new google.auth.GoogleAuth({ credentials,