Skip to content

Commit

Permalink
Handle zod validation error for invalid settings data
Browse files Browse the repository at this point in the history
  • Loading branch information
kevin-on committed Oct 24, 2024
1 parent 00c67d3 commit 57d3365
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/types/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,10 @@ const smartCopilotSettingsSchema = z.object({
export type SmartCopilotSettings = z.infer<typeof smartCopilotSettingsSchema>

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({})
}
}

0 comments on commit 57d3365

Please sign in to comment.