Error Reporting with Creator and Web Projects

Hi Everyone,

We’re working on a Creator Project that will be exporting to web. We were hoping to be able to track our errors with a service like Bugsnag. However I can’t seem to find a way to report the unhandled errors. I tried using the onerror functions and listening for error events as set out here:

But unfortunately, these do not seem to report errors made in the Creator code. I have set up a error in a main class:

this.foo = void 0;
this.foo.bar();

This does not reach the two error handlers I mentioned. If anyone knows what I’m missing, or if there’s a hook within creator that I can attach to, it would be greatly appreciated. Thanks!

Edit: Doing some more digging, it seems like it may be related to Promises somehow.

typescript.js:35 Uncaught (in promise) Error: This here be a test error, for those of you listening
    at Login.<anonymous> (project.dev.js:3361)
    at step (typescript.js:64)
    at Object.next (typescript.js:45)
    at typescript.js:39
    at Promise (<anonymous>)
    at 316.window.__awaiter (typescript.js:35)
    at Login.onLoad (project.dev.js:3358)
    at CCClass.eval [as _invoke] (eval at createInvokeImpl (component-scheduler.js:239), <anonymous>:3:65)
    at CCClass.invoke (component-scheduler.js:137)
    at CCClass.activateNode (node-activator.js:196)

This error does not seem to get recorded. But I’m not sure where else I would grab it, so that it could be forwarded to the reporter.

I have similar situation. And I can catch errors like below:

  1. Test.ts is like this:
  const { ccclass, property } = cc._decorator;
  
  @ccclass
  export default class NewClass extends cc.Component {
      foo: any;
  
      onLoad() {
          this.foo = void 0;
          this.foo.bar();
      }
  }
  
  window.onerror = function myErrorHandler(errorMsg, url, lineNumber) {
      console.log(errorMsg, url, lineNumber)
      return false;
  }
  1. Attach Test.ts to Canvas (or other Nodes)

  2. Build project for Web Mobile Platform.

  3. Host built files on web server. And Browse index.html

  4. Error will be happened like this:

project.js:1 Uncaught TypeError: Cannot read property 'bar' of undefined
    at o.onLoad (project.js:1)
    at Object.eval [as _invoke] (eval at o (cocos2d-js-min.js:9), <anonymous>:3:65)
    at Object.invoke (cocos2d-js-min.js:9)
    at Object.activateNode (cocos2d-js-min.js:17)
    at Object._activate (cocos2d-js-min.js:7)
    at e.runSceneImmediate (cocos2d-js-min.js:5)
    at cocos2d-js-min.js:5
    at s.<anonymous> (cocos2d-js-min.js:18)
    at cocos2d-js-min.js:16
    at cocos2d-js-min.js:21

However, I can’t catch errors in production enviroment becuase of Cross-Origin settings :’-(

Thank you for your input @nshmura

Good to know we’re not the only ones running into this issue. I’ll let you know if I find any solutions to this.