11import * as vscode from "vscode"
2+ import { ZodError } from "zod"
23
34import {
45 PROVIDER_SETTINGS_KEYS ,
@@ -15,6 +16,7 @@ import {
1516 isSecretStateKey ,
1617} from "../../schemas"
1718import { logger } from "../../utils/logging"
19+ import { telemetryService } from "../../services/telemetry/TelemetryService"
1820
1921type GlobalStateKey = keyof GlobalState
2022type SecretStateKey = keyof SecretState
@@ -157,8 +159,10 @@ export class ContextProxy {
157159 try {
158160 return globalSettingsSchema . parse ( values )
159161 } catch ( error ) {
160- // Log to Posthog?
161- // We'll want to know about bad type assumptions or bad ExtensionState data.
162+ if ( error instanceof ZodError ) {
163+ telemetryService . captureSchemaValidationError ( { schemaName : "GlobalSettings" , error } )
164+ }
165+
162166 return GLOBAL_SETTINGS_KEYS . reduce ( ( acc , key ) => ( { ...acc , [ key ] : values [ key ] } ) , { } as GlobalSettings )
163167 }
164168 }
@@ -173,8 +177,10 @@ export class ContextProxy {
173177 try {
174178 return providerSettingsSchema . parse ( values )
175179 } catch ( error ) {
176- // Log to Posthog?
177- // We'll want to know about bad type assumptions or bad ExtensionState data.
180+ if ( error instanceof ZodError ) {
181+ telemetryService . captureSchemaValidationError ( { schemaName : "ProviderSettings" , error } )
182+ }
183+
178184 return PROVIDER_SETTINGS_KEYS . reduce ( ( acc , key ) => ( { ...acc , [ key ] : values [ key ] } ) , { } as ProviderSettings )
179185 }
180186 }
@@ -225,7 +231,10 @@ export class ContextProxy {
225231 const globalSettings = globalSettingsExportSchema . parse ( this . getValues ( ) )
226232 return Object . fromEntries ( Object . entries ( globalSettings ) . filter ( ( [ _ , value ] ) => value !== undefined ) )
227233 } catch ( error ) {
228- console . log ( error . message )
234+ if ( error instanceof ZodError ) {
235+ telemetryService . captureSchemaValidationError ( { schemaName : "GlobalSettings" , error } )
236+ }
237+
229238 return undefined
230239 }
231240 }
0 commit comments