-
-
Notifications
You must be signed in to change notification settings - Fork 140
Closed
Milestone
Description
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
- Create a new js application
tns create test --js
- 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;
- 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.
Metadata
Metadata
Assignees
Labels
No labels