types(runtime-core): update error type to unknown (#798)
This commit is contained in:
parent
cb814f646b
commit
257727569a
@ -536,15 +536,18 @@ describe('Suspense', () => {
|
|||||||
|
|
||||||
const Comp = {
|
const Comp = {
|
||||||
setup() {
|
setup() {
|
||||||
const error = ref<Error | null>(null)
|
const errorMessage = ref<string | null>(null)
|
||||||
onErrorCaptured(e => {
|
onErrorCaptured(err => {
|
||||||
error.value = e
|
errorMessage.value =
|
||||||
|
err instanceof Error
|
||||||
|
? err.message
|
||||||
|
: `A non-Error value thrown: ${err}`
|
||||||
return true
|
return true
|
||||||
})
|
})
|
||||||
|
|
||||||
return () =>
|
return () =>
|
||||||
error.value
|
errorMessage.value
|
||||||
? h('div', error.value.message)
|
? h('div', errorMessage.value)
|
||||||
: h(Suspense, null, {
|
: h(Suspense, null, {
|
||||||
default: h(Async),
|
default: h(Async),
|
||||||
fallback: h('div', 'fallback')
|
fallback: h('div', 'fallback')
|
||||||
|
@ -41,7 +41,7 @@ export interface AppConfig {
|
|||||||
readonly isNativeTag?: (tag: string) => boolean
|
readonly isNativeTag?: (tag: string) => boolean
|
||||||
isCustomElement?: (tag: string) => boolean
|
isCustomElement?: (tag: string) => boolean
|
||||||
errorHandler?: (
|
errorHandler?: (
|
||||||
err: Error,
|
err: unknown,
|
||||||
instance: ComponentPublicInstance | null,
|
instance: ComponentPublicInstance | null,
|
||||||
info: string
|
info: string
|
||||||
) => void
|
) => void
|
||||||
|
@ -85,7 +85,7 @@ export const onRenderTracked = createHook<DebuggerHook>(
|
|||||||
)
|
)
|
||||||
|
|
||||||
export type ErrorCapturedHook = (
|
export type ErrorCapturedHook = (
|
||||||
err: Error,
|
err: unknown,
|
||||||
instance: ComponentPublicInstance | null,
|
instance: ComponentPublicInstance | null,
|
||||||
info: string
|
info: string
|
||||||
) => boolean | void
|
) => boolean | void
|
||||||
|
@ -78,7 +78,7 @@ export function callWithAsyncErrorHandling(
|
|||||||
if (isFunction(fn)) {
|
if (isFunction(fn)) {
|
||||||
const res = callWithErrorHandling(fn, instance, type, args)
|
const res = callWithErrorHandling(fn, instance, type, args)
|
||||||
if (res != null && !res._isVue && isPromise(res)) {
|
if (res != null && !res._isVue && isPromise(res)) {
|
||||||
res.catch((err: Error) => {
|
res.catch(err => {
|
||||||
handleError(err, instance, type)
|
handleError(err, instance, type)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -93,7 +93,7 @@ export function callWithAsyncErrorHandling(
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function handleError(
|
export function handleError(
|
||||||
err: Error,
|
err: unknown,
|
||||||
instance: ComponentInternalInstance | null,
|
instance: ComponentInternalInstance | null,
|
||||||
type: ErrorTypes
|
type: ErrorTypes
|
||||||
) {
|
) {
|
||||||
@ -136,7 +136,7 @@ export function setErrorRecovery(value: boolean) {
|
|||||||
forceRecover = value
|
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.
|
// default behavior is crash in prod & test, recover in dev.
|
||||||
if (__DEV__ && (forceRecover || !__TEST__)) {
|
if (__DEV__ && (forceRecover || !__TEST__)) {
|
||||||
const info = ErrorTypeStrings[type]
|
const info = ErrorTypeStrings[type]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user