Skip to content

feat(vue): Export Vue exception capture helper - #24586

Closed
vansh-nagar wants to merge 4 commits into
getsentry:developfrom
vansh-nagar:feat/export-vue-error-handler
Closed

vansh-nagar wants to merge 4 commits into
getsentry:developfrom
vansh-nagar:feat/export-vue-error-handler

Conversation

@vansh-nagar

Copy link
Copy Markdown

Exports captureVueException from @sentry/vue together with its ViewModel type. The helper applies the same component metadata and mechanism data as the automatic Vue handler, but captures synchronously so an onErrorCaptured boundary can call it inside withScope without losing per-error scope data across a timer.

The automatic application handler still defers capture to the next event loop and now shares the metadata-building path with the public helper.

Validated with the focused 14-test Vue error-handler suite, the Vue dependency-aware type build, and type-aware package lint.

Fixes #11471

Co-Authored-By: OpenAI/ChatGPT <codex@openai.com>
@vansh-nagar
vansh-nagar marked this pull request as ready for review September 22, 2026 11:45
@vansh-nagar
vansh-nagar requested a review from a team as a code owner September 22, 2026 11:45
@vansh-nagar
vansh-nagar requested review from nicohrubec and s1gr1d and removed request for a team September 22, 2026 11:45

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Want reviews to match your repository better? Bugbot Learning can learn team-specific rules from PR activity. A team admin can enable Learning in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit f52f52b. Configure here.

Comment thread packages/vue/src/errorhandler.ts
Comment thread packages/vue/test/errorHandler.test.ts
Co-Authored-By: OpenAI Codex <codex@openai.com>
Comment thread packages/vue/src/errorhandler.ts
Co-Authored-By: OpenAI Codex <codex@openai.com>
@github-actions

Copy link
Copy Markdown
Contributor

👋 @nicohrubec, @s1gr1d — Please review this PR when you get a chance!

@Lms24

Lms24 commented Sep 25, 2026

Copy link
Copy Markdown
Member

hey @vansh-nagar thanks for opening this PR! do you need this new helper yourself, or did you pick up the issue because it was still open?

@vansh-nagar

Copy link
Copy Markdown
Author

Thanks for checking. I picked this up because the issue was still open; I do not currently need the helper in my own project. If the use case is no longer something you want to support, I am happy to close it. Otherwise I can adjust the implementation to match the API you would prefer.

Co-Authored-By: OpenAI Codex <codex@openai.com>
Comment on lines 29 to 32
// Capture exception in the next event loop, to make sure that all breadcrumbs are recorded in time.
setTimeout(() => {
captureException(error, {
captureContext: { contexts: { vue: metadata } },
mechanism: { handled: !!originalErrorHandler, type: 'auto.function.vue.error_handler' },
});
captureVueExceptionWithMechanism(error, vm, lifecycleHook, !!originalErrorHandler, options);
});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Metadata computation is now deferred via setTimeout, which can lead to capturing stale or incomplete component information if the component tree changes before the timer fires.
Severity: LOW

Suggested Fix

Capture the component metadata synchronously when the error is first handled, before scheduling the setTimeout. Pass the collected metadata object into the setTimeout callback. This ensures the metadata reflects the component's state at the exact moment of the error, restoring the previous, more reliable behavior.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.

Location: packages/vue/src/errorhandler.ts#L29-L32

Potential issue: The automatic error handler in `attachErrorHandler` now defers the
computation of Vue component metadata to a `setTimeout` callback. Previously, this
metadata was captured synchronously when an error occurred. This change introduces a
potential race condition. If a component's state changes or it unmounts between the
error event and the execution of the `setTimeout` callback on the next event loop tick,
the captured metadata could be stale or incomplete. This can result in a less accurate
component trace, as the logic relies on walking the `$parent` chain which might be
altered, degrading the quality of the error report.

@Lms24

Lms24 commented Sep 28, 2026

Copy link
Copy Markdown
Member

@vansh-nagar thanks for getting back to me! I believe this issue went stale for a while and it doesn't seem like more people requested a feature like this in the meantime. I'm going to close the PR, and I just also closed the issue. Sorry for the troubles!

If this issue gets reopened, I'm happy to revisit your PR!

@Lms24 Lms24 closed this Sep 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Export @sentry/vue errorHandler

2 participants