Skip to content

execution error in invokeWithErrorHandling #12541

Open
@superMeili

Description

@superMeili

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions