|
@@ -2,7 +2,7 @@ import { pauseTracking, resetTracking } from '@vue/reactivity'
|
|
|
import type { VNode } from './vnode'
|
|
import type { VNode } from './vnode'
|
|
|
import type { ComponentInternalInstance } from './component'
|
|
import type { ComponentInternalInstance } from './component'
|
|
|
import { popWarningContext, pushWarningContext, warn } from './warning'
|
|
import { popWarningContext, pushWarningContext, warn } from './warning'
|
|
|
-import { isArray, isFunction, isPromise } from '@vue/shared'
|
|
|
|
|
|
|
+import { EMPTY_OBJ, isArray, isFunction, isPromise } from '@vue/shared'
|
|
|
import { LifecycleHooks } from './enums'
|
|
import { LifecycleHooks } from './enums'
|
|
|
|
|
|
|
|
// contexts where user provided function may be executed, in addition to
|
|
// contexts where user provided function may be executed, in addition to
|
|
@@ -111,7 +111,9 @@ export function handleError(
|
|
|
type: ErrorTypes,
|
|
type: ErrorTypes,
|
|
|
throwInDev = true,
|
|
throwInDev = true,
|
|
|
) {
|
|
) {
|
|
|
- const contextVNode = instance ? instance.vnode : null
|
|
|
|
|
|
|
+ const contextVNode = instance && instance.vnode
|
|
|
|
|
+ const { errorHandler, throwUnhandledErrorInProduction } =
|
|
|
|
|
+ (instance && instance.appContext.config) || EMPTY_OBJ
|
|
|
if (instance) {
|
|
if (instance) {
|
|
|
let cur = instance.parent
|
|
let cur = instance.parent
|
|
|
// the exposed instance is the render proxy to keep it consistent with 2.x
|
|
// the exposed instance is the render proxy to keep it consistent with 2.x
|
|
@@ -134,20 +136,18 @@ export function handleError(
|
|
|
cur = cur.parent
|
|
cur = cur.parent
|
|
|
}
|
|
}
|
|
|
// app-level handling
|
|
// app-level handling
|
|
|
- const appErrorHandler = instance.appContext.config.errorHandler
|
|
|
|
|
- if (appErrorHandler) {
|
|
|
|
|
|
|
+ if (errorHandler) {
|
|
|
pauseTracking()
|
|
pauseTracking()
|
|
|
- callWithErrorHandling(
|
|
|
|
|
- appErrorHandler,
|
|
|
|
|
- null,
|
|
|
|
|
- ErrorCodes.APP_ERROR_HANDLER,
|
|
|
|
|
- [err, exposedInstance, errorInfo],
|
|
|
|
|
- )
|
|
|
|
|
|
|
+ callWithErrorHandling(errorHandler, null, ErrorCodes.APP_ERROR_HANDLER, [
|
|
|
|
|
+ err,
|
|
|
|
|
+ exposedInstance,
|
|
|
|
|
+ errorInfo,
|
|
|
|
|
+ ])
|
|
|
resetTracking()
|
|
resetTracking()
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- logError(err, type, contextVNode, throwInDev)
|
|
|
|
|
|
|
+ logError(err, type, contextVNode, throwInDev, throwUnhandledErrorInProduction)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function logError(
|
|
function logError(
|
|
@@ -155,6 +155,7 @@ function logError(
|
|
|
type: ErrorTypes,
|
|
type: ErrorTypes,
|
|
|
contextVNode: VNode | null,
|
|
contextVNode: VNode | null,
|
|
|
throwInDev = true,
|
|
throwInDev = true,
|
|
|
|
|
+ throwInProd = false,
|
|
|
) {
|
|
) {
|
|
|
if (__DEV__) {
|
|
if (__DEV__) {
|
|
|
const info = ErrorTypeStrings[type]
|
|
const info = ErrorTypeStrings[type]
|
|
@@ -171,6 +172,8 @@ function logError(
|
|
|
} else if (!__TEST__) {
|
|
} else if (!__TEST__) {
|
|
|
console.error(err)
|
|
console.error(err)
|
|
|
}
|
|
}
|
|
|
|
|
+ } else if (throwInProd) {
|
|
|
|
|
+ throw err
|
|
|
} else {
|
|
} else {
|
|
|
// recover in prod to reduce the impact on end-user
|
|
// recover in prod to reduce the impact on end-user
|
|
|
console.error(err)
|
|
console.error(err)
|