vue icon indicating copy to clipboard operation
vue copied to clipboard

execution error in invokeWithErrorHandling

Open superMeili opened this issue 1 year ago • 0 comments

Version

2.6.14

Reproduction link

github.com

Steps to reproduce

export default {
  name: 'test',
  template: '<div>test</div>',
  created() {
    return Promise.reject()
  }
}

or

export default {
  name: 'test',
  template: '<div>test</div>',
  async created() {
    await Promise.reject()
  }
}

What is expected?

normal error format in vue

What is actually happening?

vue.runtime.esm.js?2b0e:1884 Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'toString') at logError (vue.runtime.esm.js?2b0e:1884:1) at globalHandleError (vue.runtime.esm.js?2b0e:1879:1) at handleError (vue.runtime.esm.js?2b0e:1839:1) at eval (vue.runtime.esm.js?2b0e:1856:1)


I read the relevant source code

I think it can be resolved this way


function logError (err, vm, info) {
  if (process.env.NODE_ENV !== 'production') {
    // warn(`Error in ${info}: "${err.toString()}"`, vm)
    // change the 'err.toString()' to 'String(err)'
    warn(`Error in ${info}: "${String(err)}"`, vm)
  }
  /* istanbul ignore else */
  if ((inBrowser || inWeex) && typeof console !== 'undefined') {
    console.error(err)
  } else {
    throw err
  }
}

This way you can normally throw errors and trace back to the source

superMeili avatar May 23 '22 06:05 superMeili