Skip to content

Unify exceptions information in try/catch and __onUncaughtError #1445

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
vtrifonov opened this issue Aug 14, 2019 · 2 comments
Closed

Unify exceptions information in try/catch and __onUncaughtError #1445

vtrifonov opened this issue Aug 14, 2019 · 2 comments
Milestone

Comments

@vtrifonov
Copy link
Contributor

Describe the bug
If you trhow an Error in try/catch the stack and stackTrace fields show different information than if the error is handled in the global.__onUncaughtError

To Reproduce

  1. Create a new js application tns create test --js
  2. Open app/main-view-model and replace its content with the following:
const Observable = require("tns-core-modules/data/observable").Observable;

global.__onUncaughtError = (err) => {
  console.log("UNCAUGHT MESSAGE:", err.message);
  console.log("UNCAUGHT STACK:", err.stack);
  console.log("UNCAUGHT STACKTRACE:", err.stackTrace);
}

function createViewModel() {
  const viewModel = new Observable();

  viewModel.onTap = () => {
      try {
          throw new Error("Test");
      } catch (err) {
          console.log("CAUGHT MESSAGE:", err.message);
          console.log("CAUGHT STACK:", err.stack);
          console.log("CAUGHT STACKTRACE:", err.stackTrace);
      }
      throw new Error("Test");
  };

  return viewModel;
}

exports.createViewModel = createViewModel;
  1. Run the application and press the button

In the CLI output you will see:

JS: CAUGHT MESSAGE: Test
JS: CAUGHT STACK: Error: Test
JS:     at Observable.viewModel.onTap file:///app/main-view-model.js:14:0
JS:     at Button.push.../node_modules/tns-core-modules/data/observable/observable.js.Observable.notify file:///node_modules/tns-core-modules/data/observable/observable.js:107:0
JS:     at Button.push.../node_modules/tns-core-modules/data/observable/observable.js.Observable._emit file:///node_modules/tns-core-modules/data/observable/observable.js:127:0
JS:     at Object.ClickListenerImpl.onClick file:///node_modules/tns-core-modules/ui/button/button.js:29:0
JS: CAUGHT STACKTRACE: undefined
..........
JS: UNCAUGHT MESSAGE: Calling js method onClick failed
JS: Error: Test
JS: UNCAUGHT STACK: Error: Calling js method onClick failed
JS: Error: Test
JS: UNCAUGHT STACKTRACE: 	viewModel.onTapfile:///app/main-view-model.js:20:0
JS: 	at push.../node_modules/tns-core-modules/data/observable/observable.js.Observable.notifyfile:///node_modules/tns-core-modules/data/observable/observable.js:107:0
JS: 	at push.../node_modules/tns-core-modules/data/observable/observable.js.Observable._emitfile:///node_modules/tns-core-modules/data/observable/observable.js:127:0
JS: 	at ClickListenerImpl.onClickfile:///node_modules/tns-core-modules/ui/button/button.js:29:0
JS: 	at com.tns.Runtime.callJSMethodNative(Native Method)
JS: 	at com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1209)
JS: 	at com.tns.Runtime.callJSMethodImpl(Runtime.java:1096)
JS: 	at com.tns.Runtime.callJSMethod(Runtime.java:1083)
JS: 	at com.tns.Runtime.callJSMethod(Runtime.java:1063)
JS: 	at com.tns.Runtime.callJSMethod(Runtime.java:1055)
JS: 	at com.tns.gen.java.lang.Object_vendor_14594_32_ClickListenerImpl.onClick(Object_vendor_14594_32_ClickListenerImpl.java:18)
JS: 	at android.view.View.performClick(View.java...

as you can see the CAUGHT and UNCAUGHT stack and stackTrace differ a lot

Expected behavior
The stack and stackTrace properties should be the same in both cases. stack should contain the JS error and stackTrace should contain both.

Additional context
Check the same functionality in iOS runtime.

@vtrifonov
Copy link
Contributor Author

Actually the "stackTrace" property, in that case, cannot be set as there is no native code and the exception doesn't get to the runtime code as it is handled in V8.

@vtrifonov vtrifonov added this to the 6.2.0 milestone Oct 10, 2019
@farfromrefug
Copy link
Contributor

I agree but should nt the stack format be the same? Makes it harder to parse if both have different format(I parse it in my bugsnag plugin)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants