Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle updated Vue error info URL #2068

Merged
merged 2 commits into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## TBD

### Fixed

- (plugin-vue) Handle updated Vue error info URL [#2068](https://github.com/bugsnag/bugsnag-js/pull/2068)

## v7.22.3 (2024-01-03)

### Changed
Expand Down
14 changes: 8 additions & 6 deletions packages/plugin-vue/src/vue.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module.exports = (app, client) => {

// In Vue 3.4+, the info param is a link to the Vue error docs in prod, so we need to extract the error code from it
// https://github.com/vuejs/core/pull/9165/commits/c261beab2c0a26e401f2c3d5eae2e4c41de6fe4d
const code = typeof info === 'string' && info.indexOf('-') > 0 ? info.split('-')[1] : info
const code = typeof info === 'string' && info.indexOf('runtime-') > 0 ? info.split('runtime-')[1] : info
const errorInfo = ErrorTypeStrings[code] || info

event.addMetadata('vue', {
Expand All @@ -33,7 +33,7 @@ function formatComponentName (vm) {
// We copy in the following data structures from Vue's source so we can map the "info" parameter in the errorhandler
// callback (which is supplied as either a string or int) back to something meaningful

// https://github.com/vuejs/vue-next/blob/d5cce47789db8f37b9f5f8ea6602ea63e3a04b07/packages/runtime-core/src/component.ts#L153-L167
// https://github.com/vuejs/core/blob/f1068fc60ca511f68ff0aaedcc18b39124791d29/packages/runtime-core/src/enums.ts
const LifecycleHooks = {
BEFORE_CREATE: 'bc',
CREATED: 'c',
Expand All @@ -47,10 +47,11 @@ const LifecycleHooks = {
ACTIVATED: 'a',
RENDER_TRIGGERED: 'rtg',
RENDER_TRACKED: 'rtc',
ERROR_CAPTURED: 'ec'
ERROR_CAPTURED: 'ec',
SERVER_PREFETCH: 'sp'
}

// https://github.com/vuejs/vue-next/blob/d5cce47789db8f37b9f5f8ea6602ea63e3a04b07/packages/runtime-core/src/errorHandling.ts#L6-L24
// https://github.com/vuejs/core/blob/f1068fc60ca511f68ff0aaedcc18b39124791d29/packages/runtime-core/src/errorHandling.ts#L7-L25
const ErrorCodes = {
SETUP_FUNCTION: 0,
RENDER_FUNCTION: 1,
Expand All @@ -69,8 +70,9 @@ const ErrorCodes = {
SCHEDULER: 14
}

// https://github.com/vuejs/vue-next/blob/d5cce47789db8f37b9f5f8ea6602ea63e3a04b07/packages/runtime-core/src/errorHandling.ts#L26-L57
// https://github.com/vuejs/core/blob/f1068fc60ca511f68ff0aaedcc18b39124791d29/packages/runtime-core/src/errorHandling.ts#L27-L59
const ErrorTypeStrings = {
[LifecycleHooks.SERVER_PREFETCH]: 'serverPrefetch hook',
[LifecycleHooks.BEFORE_CREATE]: 'beforeCreate hook',
[LifecycleHooks.CREATED]: 'created hook',
[LifecycleHooks.BEFORE_MOUNT]: 'beforeMount hook',
Expand Down Expand Up @@ -100,5 +102,5 @@ const ErrorTypeStrings = {
[ErrorCodes.ASYNC_COMPONENT_LOADER]: 'async component loader',
[ErrorCodes.SCHEDULER]:
'scheduler flush. This is likely a Vue internals bug. ' +
'Please open an issue at https://new-issue.vuejs.org/?repo=vuejs/vue-next'
'Please open an issue at https://github.com/vuejs/core .'
}
2 changes: 1 addition & 1 deletion packages/plugin-vue/test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ describe('bugsnag vue', () => {
}))
expect(typeof mockVueApp.config.errorHandler).toBe('function')
const errorHandler = mockVueApp.config.errorHandler as unknown as Vue3ErrorHandler
errorHandler(new Error('oops'), { $options: { name: 'MyComponent' } }, 'https://vuejs.org/errors/#runtime-1')
errorHandler(new Error('oops'), { $options: { name: 'MyComponent' } }, 'https://vuejs.org/error-reference/#runtime-1')
})

it('tolerates unmappable info paramater', done => {
Expand Down
Loading