} from './componentProps'
import { Slots, initSlots, InternalSlots } from './componentSlots'
import { warn } from './warning'
-import { ErrorCodes, callWithAsyncErrorHandling } from './errorHandling'
+import { ErrorCodes, callWithErrorHandling, handleError } from './errorHandling'
import { AppContext, createAppContext, AppConfig } from './apiCreateApp'
import { Directive, validateDirectiveName } from './directives'
import {
currentInstance = instance
pauseTracking()
- const setupResult = callWithAsyncErrorHandling(
+ const setupResult = callWithErrorHandling(
setup,
instance,
ErrorCodes.SETUP_FUNCTION,
if (isPromise(setupResult)) {
if (isSSR) {
// return the promise so server-renderer can wait on it
- return setupResult.then((resolvedResult: unknown) => {
- handleSetupResult(instance, resolvedResult, isSSR)
- })
+ return setupResult
+ .then((resolvedResult: unknown) => {
+ handleSetupResult(instance, resolvedResult, isSSR)
+ })
+ .catch(e => {
+ handleError(e, instance, ErrorCodes.SETUP_FUNCTION)
+ })
} else if (__FEATURE_SUSPENSE__) {
// async setup returned Promise.
// bail here and wait for re-entry.
test('reject', async () => {
const Comp = {
+ errorCaptured: jest.fn(() => false),
render() {
return h(Suspense, null, {
default: h(RejectingAsync),
}
expect(await renderToString(createApp(Comp))).toBe(`<!---->`)
- expect('Uncaught error in async setup').toHaveBeenWarned()
- expect(
- 'Unhandled error during execution of setup function'
- ).toHaveBeenWarned()
+
+ expect(Comp.errorCaptured).toHaveBeenCalledTimes(1)
expect('missing template').toHaveBeenWarned()
})
test('resolving component + rejecting component', async () => {
const Comp = {
+ errorCaptured: jest.fn(() => false),
render() {
return h(Suspense, null, {
default: h('div', [h(ResolvingAsync), h(RejectingAsync)]),
expect(await renderToString(createApp(Comp))).toBe(
`<div><div>async</div><!----></div>`
)
- expect('Uncaught error in async setup').toHaveBeenWarned()
- expect(
- 'Unhandled error during execution of setup function'
- ).toHaveBeenWarned()
+
+ expect(Comp.errorCaptured).toHaveBeenCalledTimes(1)
expect('missing template or render function').toHaveBeenWarned()
})
test('failing suspense in passing suspense', async () => {
const Comp = {
+ errorCaptured: jest.fn(() => false),
render() {
return h(Suspense, null, {
default: h('div', [
expect(await renderToString(createApp(Comp))).toBe(
`<div><div>async</div><div><!----></div></div>`
)
- expect('Uncaught error in async setup').toHaveBeenWarned()
- expect(
- 'Unhandled error during execution of setup function'
- ).toHaveBeenWarned()
+
+ expect(Comp.errorCaptured).toHaveBeenCalledTimes(1)
expect('missing template').toHaveBeenWarned()
})
test('passing suspense in failing suspense', async () => {
const Comp = {
+ errorCaptured: jest.fn(() => false),
render() {
return h(Suspense, null, {
default: h('div', [
expect(await renderToString(createApp(Comp))).toBe(
`<div><!----><div><div>async</div></div></div>`
)
- expect('Uncaught error in async setup').toHaveBeenWarned()
- expect(
- 'Unhandled error during execution of setup function'
- ).toHaveBeenWarned()
+ expect(Comp.errorCaptured).toHaveBeenCalledTimes(1)
expect('missing template').toHaveBeenWarned()
})
})
const hasAsyncSetup = isPromise(res)
const prefetch = (vnode.type as ComponentOptions).serverPrefetch
if (hasAsyncSetup || prefetch) {
- let p = hasAsyncSetup
- ? (res as Promise<void>).catch(err => {
- warn(`[@vue/server-renderer]: Uncaught error in async setup:\n`, err)
- })
- : Promise.resolve()
+ let p = hasAsyncSetup ? (res as Promise<void>) : Promise.resolve()
if (prefetch) {
p = p.then(() => prefetch.call(instance.proxy)).catch(err => {
warn(`[@vue/server-renderer]: Uncaught error in serverPrefetch:\n`, err)