const Comp = {
setup() {
- const error = ref<Error | null>(null)
- onErrorCaptured(e => {
- error.value = e
+ const errorMessage = ref<string | null>(null)
+ onErrorCaptured(err => {
+ errorMessage.value =
+ err instanceof Error
+ ? err.message
+ : `A non-Error value thrown: ${err}`
return true
})
return () =>
- error.value
- ? h('div', error.value.message)
+ errorMessage.value
+ ? h('div', errorMessage.value)
: h(Suspense, null, {
default: h(Async),
fallback: h('div', 'fallback')
if (isFunction(fn)) {
const res = callWithErrorHandling(fn, instance, type, args)
if (res != null && !res._isVue && isPromise(res)) {
- res.catch((err: Error) => {
+ res.catch(err => {
handleError(err, instance, type)
})
}
}
export function handleError(
- err: Error,
+ err: unknown,
instance: ComponentInternalInstance | null,
type: ErrorTypes
) {
forceRecover = value
}
-function logError(err: Error, type: ErrorTypes, contextVNode: VNode | null) {
+function logError(err: unknown, type: ErrorTypes, contextVNode: VNode | null) {
// default behavior is crash in prod & test, recover in dev.
if (__DEV__ && (forceRecover || !__TEST__)) {
const info = ErrorTypeStrings[type]