import { isFunction , isPromise } from '@vue/shared' ; export function callWithErrorHandling ( fn , type , args ? ) { let res ; try { res = args ? fn ( ... args ) : fn ( ) ; } catch ( err ) { handleError ( err , type ) ; } return res ; } export function callWithAsyncErrorHandling ( fn , type , args ? ) { if ( isFunction ( fn ) ) { const res = callWithErrorHandling ( fn , type , args ) ; if ( res && isPromise ( res ) ) { res . catch ( ( err ) => { handleError ( err , type ) ; } ) ; } return res ; } const values = [ ] ; for ( let i = 0 ; i < fn . length ; i ++ ) values . push ( callWithAsyncErrorHandling ( fn [ i ] , type , args ) ) ; return values ; } export function handleError ( err , type ) { console . error ( new Error ( `[@vue-reactivity/watch]: ${ type }` ) ) ; console . error ( err ) ; } export function raise ( message ) { throw createError ( message ) ; } export function warn ( message ) { console . warn ( createError ( message ) ) ; } export function createError ( message ) { return new Error ( `[reactivue]: ${ message }` ) ; }