@@ -2,7 +2,7 @@ import { pauseTracking, resetTracking } from '@vue/reactivity'
2
2
import type { VNode } from './vnode'
3
3
import type { ComponentInternalInstance } from './component'
4
4
import { popWarningContext , pushWarningContext , warn } from './warning'
5
- import { isArray , isFunction , isPromise } from '@vue/shared'
5
+ import { EMPTY_OBJ , isArray , isFunction , isPromise } from '@vue/shared'
6
6
import { LifecycleHooks } from './enums'
7
7
8
8
// contexts where user provided function may be executed, in addition to
@@ -111,7 +111,9 @@ export function handleError(
111
111
type : ErrorTypes ,
112
112
throwInDev = true ,
113
113
) {
114
- const contextVNode = instance ? instance . vnode : null
114
+ const contextVNode = instance && instance . vnode
115
+ const { errorHandler, throwUnhandledErrorInProduction } =
116
+ ( instance && instance . appContext . config ) || EMPTY_OBJ
115
117
if ( instance ) {
116
118
let cur = instance . parent
117
119
// the exposed instance is the render proxy to keep it consistent with 2.x
@@ -134,27 +136,26 @@ export function handleError(
134
136
cur = cur . parent
135
137
}
136
138
// app-level handling
137
- const appErrorHandler = instance . appContext . config . errorHandler
138
- if ( appErrorHandler ) {
139
+ if ( errorHandler ) {
139
140
pauseTracking ( )
140
- callWithErrorHandling (
141
- appErrorHandler ,
142
- null ,
143
- ErrorCodes . APP_ERROR_HANDLER ,
144
- [ err , exposedInstance , errorInfo ] ,
145
- )
141
+ callWithErrorHandling ( errorHandler , null , ErrorCodes . APP_ERROR_HANDLER , [
142
+ err ,
143
+ exposedInstance ,
144
+ errorInfo ,
145
+ ] )
146
146
resetTracking ( )
147
147
return
148
148
}
149
149
}
150
- logError ( err , type , contextVNode , throwInDev )
150
+ logError ( err , type , contextVNode , throwInDev , throwUnhandledErrorInProduction )
151
151
}
152
152
153
153
function logError (
154
154
err : unknown ,
155
155
type : ErrorTypes ,
156
156
contextVNode : VNode | null ,
157
157
throwInDev = true ,
158
+ throwInProd = false ,
158
159
) {
159
160
if ( __DEV__ ) {
160
161
const info = ErrorTypeStrings [ type ]
@@ -171,6 +172,8 @@ function logError(
171
172
} else if ( ! __TEST__ ) {
172
173
console . error ( err )
173
174
}
175
+ } else if ( throwInProd ) {
176
+ throw err
174
177
} else {
175
178
// recover in prod to reduce the impact on end-user
176
179
console . error ( err )
0 commit comments