]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
types(runtime-core): update error type to unknown (#798)
authorhareku <hareku908@gmail.com>
Mon, 9 Mar 2020 19:58:52 +0000 (04:58 +0900)
committerGitHub <noreply@github.com>
Mon, 9 Mar 2020 19:58:52 +0000 (15:58 -0400)
packages/runtime-core/__tests__/components/Suspense.spec.ts
packages/runtime-core/src/apiCreateApp.ts
packages/runtime-core/src/apiLifecycle.ts
packages/runtime-core/src/errorHandling.ts

index 1191440684c7b1f3bfd6072f7418fb24201489a1..555a6de2194c3c3cf55927e253d3ac3434d7c5e7 100644 (file)
@@ -536,15 +536,18 @@ describe('Suspense', () => {
 
     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')
index 5e6acb9cd0a6e440ed96c92c98f89ba4afaa0cc8..73ecd8480d1779e7bd583516d3ba648b6e2cb0d9 100644 (file)
@@ -41,7 +41,7 @@ export interface AppConfig {
   readonly isNativeTag?: (tag: string) => boolean
   isCustomElement?: (tag: string) => boolean
   errorHandler?: (
-    err: Error,
+    err: unknown,
     instance: ComponentPublicInstance | null,
     info: string
   ) => void
index 4ee86b60c218a7a99c9272f313731578221ea171..ccb26710e91cf5482807050b9aa34309e99e34d7 100644 (file)
@@ -85,7 +85,7 @@ export const onRenderTracked = createHook<DebuggerHook>(
 )
 
 export type ErrorCapturedHook = (
-  err: Error,
+  err: unknown,
   instance: ComponentPublicInstance | null,
   info: string
 ) => boolean | void
index 0d965c63c0c12d588d8a34515f5b6648f4883170..d9a0fc0b6e2670dd843c32eac518c5d7f6df205b 100644 (file)
@@ -78,7 +78,7 @@ export function callWithAsyncErrorHandling(
   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)
       })
     }
@@ -93,7 +93,7 @@ export function callWithAsyncErrorHandling(
 }
 
 export function handleError(
-  err: Error,
+  err: unknown,
   instance: ComponentInternalInstance | null,
   type: ErrorTypes
 ) {
@@ -136,7 +136,7 @@ export function setErrorRecovery(value: boolean) {
   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]