Skip to content

Commit 2577275

Browse files
authored
types(runtime-core): update error type to unknown (#798)
1 parent cb814f6 commit 2577275

File tree

4 files changed

+13
-10
lines changed

4 files changed

+13
-10
lines changed

packages/runtime-core/__tests__/components/Suspense.spec.ts

+8-5
Original file line numberDiff line numberDiff line change
@@ -536,15 +536,18 @@ describe('Suspense', () => {
536536

537537
const Comp = {
538538
setup() {
539-
const error = ref<Error | null>(null)
540-
onErrorCaptured(e => {
541-
error.value = e
539+
const errorMessage = ref<string | null>(null)
540+
onErrorCaptured(err => {
541+
errorMessage.value =
542+
err instanceof Error
543+
? err.message
544+
: `A non-Error value thrown: ${err}`
542545
return true
543546
})
544547

545548
return () =>
546-
error.value
547-
? h('div', error.value.message)
549+
errorMessage.value
550+
? h('div', errorMessage.value)
548551
: h(Suspense, null, {
549552
default: h(Async),
550553
fallback: h('div', 'fallback')

packages/runtime-core/src/apiCreateApp.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export interface AppConfig {
4141
readonly isNativeTag?: (tag: string) => boolean
4242
isCustomElement?: (tag: string) => boolean
4343
errorHandler?: (
44-
err: Error,
44+
err: unknown,
4545
instance: ComponentPublicInstance | null,
4646
info: string
4747
) => void

packages/runtime-core/src/apiLifecycle.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ export const onRenderTracked = createHook<DebuggerHook>(
8585
)
8686

8787
export type ErrorCapturedHook = (
88-
err: Error,
88+
err: unknown,
8989
instance: ComponentPublicInstance | null,
9090
info: string
9191
) => boolean | void

packages/runtime-core/src/errorHandling.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ export function callWithAsyncErrorHandling(
7878
if (isFunction(fn)) {
7979
const res = callWithErrorHandling(fn, instance, type, args)
8080
if (res != null && !res._isVue && isPromise(res)) {
81-
res.catch((err: Error) => {
81+
res.catch(err => {
8282
handleError(err, instance, type)
8383
})
8484
}
@@ -93,7 +93,7 @@ export function callWithAsyncErrorHandling(
9393
}
9494

9595
export function handleError(
96-
err: Error,
96+
err: unknown,
9797
instance: ComponentInternalInstance | null,
9898
type: ErrorTypes
9999
) {
@@ -136,7 +136,7 @@ export function setErrorRecovery(value: boolean) {
136136
forceRecover = value
137137
}
138138

139-
function logError(err: Error, type: ErrorTypes, contextVNode: VNode | null) {
139+
function logError(err: unknown, type: ErrorTypes, contextVNode: VNode | null) {
140140
// default behavior is crash in prod & test, recover in dev.
141141
if (__DEV__ && (forceRecover || !__TEST__)) {
142142
const info = ErrorTypeStrings[type]

0 commit comments

Comments
 (0)