Skip to content
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

CB-9366 Log error.stack as it helps with diagnosing the source of the… #118

Closed
wants to merge 1 commit into from
Closed

Conversation

nikhilkh
Copy link
Contributor

@nikhilkh nikhilkh commented Jul 14, 2015

@purplecabbage
Copy link
Contributor

I would leave this to userland.
window.onerror = function(err,filename,lineNumber) { ... }

Also, on iOS this is going to look like :
callMe@file:///Users/purplecabbage/Library/Application%20Support/iPhone%20Simulator/7.1/Applications/F40363A6-5AFE-4E19-8125-A1A4C928595D/HelloCordova.app/www/js/index.js:12:13
iAmFunky@file:///Users/purplecabbage/Library/Application%20Support/iPhone%20Simulator/7.1/Applications/F40363A6-5AFE-4E19-8125-A1A4C928595D/HelloCordova.app/www/js/index.js:26:33
fire@file:///Users/purplecabbage/Library/Application%20Support/iPhone%20Simulator/7.1/Applications/F40363A6-5AFE-4E19-8125-A1A4C928595D/HelloCordova.app/www/cordova.js:750:28
file:///Users/purplecabbage/Library/Application%20Support/iPhone%20Simulator/7.1/Applications/F40363A6-5AFE-4E19-8125-A1A4C928595D/HelloCordova.app/www/cordova.js:223:53

@nikhilkh
Copy link
Contributor Author

What's the downside of adding this? This is really an exceptional scenario and should not hit commonly to clutter console log with ugly stack traces. Also, rethrowing the error will reset it's stack property - depending on which runtime and platform you are using and hence. window.onerror might not get the actual stack that caused the error.
Putting it in console.log makes sure it shows in ADB logcat, Windows debug logs - hence, it makes it easier for people to root cause such issues.

@purplecabbage
Copy link
Contributor

Not a huge deal. I was assuming that most errors here would be the result of a missing callback, in which case stack.length is 0.
In the case where the user has an error in their success/error handler this might help them, but I am still not sure how much more value they would get than window.onerror

@nikhilkh
Copy link
Contributor Author

If you have multiple calls to cordova methods and one of them might be missing a callback or passing another incorrect argument (like in a scenario similar to the recent new Media() bug) a call stack tells you in your code the line which might have resulting in that exception causing your app to crash. The bug fixed in apache/cordova-plugin-media@5f8738c would have been much easier to identify from buildBot ADB logs if we had a stack. Instead, I had to get into the debugger to identify the issue.

@jimmont
Copy link

jimmont commented Feb 3, 2016

This try-catch for callbacks is a real pain. Having access to errors as they occur is highly desirable. And there appears to be a logic error here where callbacks are never deleted if they throw an error. Isn't managing errors a responsibility outside of self.cordova? Just started looking at this javascript after a lot of problematic worker debugging.

@nikhilkh
Copy link
Contributor Author

nikhilkh commented Feb 6, 2016

@jimmont Why is the try-catch a pain? Is it because the stack gets reset here? You have a fair point about the callback not being deleted on exception scenarios.

@jimmont
Copy link

jimmont commented Feb 7, 2016

@nikhilkh Yes. Throwing errors is a reliable way of both debugging and finding problems. In fact I don't know of a more reliable way to debug. When they're intercepted I can't do that as easily. (Similar is true of cordova-plugin-console.) It's my opinion (for whatever it's worth) that making assumptions about the cause of an error, especially in a library, and especially in one that targets so many scenarios, is pretty significant. In looking through the source cordova uses a module loader and http requests to setup global APIs from the local filesystems on the device, and various events/event-system to get the sequence and setup right. Seems sub-optimal to me. (For example, a concatenated script which works with the global namespace directly seems like the simple approach, all things considered, and is what happens in the end anyway.) But I haven't finished looking at all the contemporary platforms (that I want to target anyhow). No one asked for these observations but given I'm seeing them, and how expensive time-wise it is to work either with or around them, thought I'd mention it. (In case more context is helpful: imagine debugging getting cordova and all the desired plugins working in a worker.)

@janpio
Copy link
Member

janpio commented Feb 21, 2018

@nikhilkh Is this PR still relevant? If so, could you take a look at the conflicts please?

@brodycj brodycj self-assigned this Jun 18, 2018
@brodycj
Copy link

brodycj commented Jun 18, 2018

Looks like it would be really nice to have this enhancement, maybe for the next major release.

@purplecabbage
Copy link
Contributor

purplecabbage commented Jun 18, 2018 via email

brodycj pushed a commit to brodycj/cordova-js that referenced this pull request Jun 18, 2018
brodycj pushed a commit to brodycj/cordova-js that referenced this pull request Jun 18, 2018
@brodycj brodycj mentioned this pull request Jun 18, 2018
brodycj pushed a commit to brodycj/cordova-js that referenced this pull request Jun 18, 2018
brodycj pushed a commit to brodycj/cordova-js that referenced this pull request Jun 18, 2018
brodycj pushed a commit to brodycj/cordova-js that referenced this pull request Jun 20, 2018
brodycj pushed a commit to brodycj/cordova-js that referenced this pull request Jun 20, 2018
brodycj pushed a commit to brodycj/cordova-js that referenced this pull request Jun 20, 2018
as it helps with diagnosing the source of the error

JavaScript fixed by @brodybits (Christopher J. Brody)

ref: apache#118

Co-authored-by: Nikhil Khandelwal <nikhilkh@microsoft.com>
Co-authored-by: Christopher J. Brody <chris.brody@gmail.com>
brodycj pushed a commit to brodycj/cordova-js that referenced this pull request Jun 20, 2018
as it helps with diagnosing the source of the error

JavaScript fixed by @brodybits (Christopher J. Brody)

Fixes apache#118

Co-authored-by: Nikhil Khandelwal <nikhilkh@microsoft.com>
Co-authored-by: Christopher J. Brody <chris.brody@gmail.com>
@brodycj brodycj closed this in 084512a Jun 20, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants