( err: unknown, instance: ComponentInternalInstance | null | undefined, type: ErrorTypes, throwInDev = true, )
| 110 | } |
| 111 | |
| 112 | export function handleError( |
| 113 | err: unknown, |
| 114 | instance: ComponentInternalInstance | null | undefined, |
| 115 | type: ErrorTypes, |
| 116 | throwInDev = true, |
| 117 | ): void { |
| 118 | const contextVNode = instance ? instance.vnode : null |
| 119 | const { errorHandler, throwUnhandledErrorInProduction } = |
| 120 | (instance && instance.appContext.config) || EMPTY_OBJ |
| 121 | if (instance) { |
| 122 | let cur = instance.parent |
| 123 | // the exposed instance is the render proxy to keep it consistent with 2.x |
| 124 | const exposedInstance = instance.proxy |
| 125 | // in production the hook receives only the error code |
| 126 | const errorInfo = __DEV__ |
| 127 | ? ErrorTypeStrings[type] |
| 128 | : `https://vuejs.org/error-reference/#runtime-${type}` |
| 129 | while (cur) { |
| 130 | const errorCapturedHooks = cur.ec |
| 131 | if (errorCapturedHooks) { |
| 132 | for (let i = 0; i < errorCapturedHooks.length; i++) { |
| 133 | if ( |
| 134 | errorCapturedHooks[i](err, exposedInstance, errorInfo) === false |
| 135 | ) { |
| 136 | return |
| 137 | } |
| 138 | } |
| 139 | } |
| 140 | cur = cur.parent |
| 141 | } |
| 142 | // app-level handling |
| 143 | if (errorHandler) { |
| 144 | pauseTracking() |
| 145 | callWithErrorHandling(errorHandler, null, ErrorCodes.APP_ERROR_HANDLER, [ |
| 146 | err, |
| 147 | exposedInstance, |
| 148 | errorInfo, |
| 149 | ]) |
| 150 | resetTracking() |
| 151 | return |
| 152 | } |
| 153 | } |
| 154 | logError(err, type, contextVNode, throwInDev, throwUnhandledErrorInProduction) |
| 155 | } |
| 156 | |
| 157 | function logError( |
| 158 | err: unknown, |
no test coverage detected