diff --git a/packages/vue/src/pinia.ts b/packages/vue/src/pinia.ts index 56e38c33bad7..fbccbb56cd9e 100644 --- a/packages/vue/src/pinia.ts +++ b/packages/vue/src/pinia.ts @@ -26,6 +26,12 @@ export const createSentryPiniaPlugin: (options?: SentryPiniaPluginOptions) => Pi }, ) => { const plugin: PiniaPlugin = ({ store }) => { + let transformedState = store.$state; + try { + transformedState = options.stateTransformer ? options.stateTransformer(store.$state) : store.$state; + } catch (_) { + // If stateTransformer throws, let's just use the unmodified state + } options.attachPiniaState !== false && getGlobalScope().addEventProcessor((event, hint) => { try { @@ -37,7 +43,7 @@ export const createSentryPiniaPlugin: (options?: SentryPiniaPluginOptions) => Pi ...(hint.attachments || []), { filename, - data: JSON.stringify(store.$state), + data: JSON.stringify(transformedState), }, ]; } catch (_) { @@ -66,7 +72,6 @@ export const createSentryPiniaPlugin: (options?: SentryPiniaPluginOptions) => Pi } /* Set latest state to scope */ - const transformedState = options.stateTransformer ? options.stateTransformer(store.$state) : store.$state; const scope = getCurrentScope(); const currentState = scope.getScopeData().contexts.state;