From 57d3365822e1c535325b016334450fb09d31ab01 Mon Sep 17 00:00:00 2001 From: Kwanghyun On Date: Thu, 24 Oct 2024 13:33:27 +0900 Subject: [PATCH] Handle zod validation error for invalid settings data --- src/types/settings.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/types/settings.ts b/src/types/settings.ts index 1679e4e..35ea5ed 100644 --- a/src/types/settings.ts +++ b/src/types/settings.ts @@ -20,5 +20,10 @@ const smartCopilotSettingsSchema = z.object({ export type SmartCopilotSettings = z.infer export function parseSmartCopilotSettings(data: unknown): SmartCopilotSettings { - return smartCopilotSettingsSchema.parse(data) + try { + return smartCopilotSettingsSchema.parse(data) + } catch (error) { + console.warn('Invalid settings provided, using defaults:', error) + return smartCopilotSettingsSchema.parse({}) + } }