Is it possible to get the line number of an error in React Native?

Viewed 6366

I am writing a React Native app, and I find that the error messages that the iOS emulator generates never indicate the line in my code where the error occurred. In the screenshot below, I can see that this is a problem with the map() function in the Dashboard component, but since it doesn't give a line number, if there are multiple instances of map() in Dashboard, I don't know how to isolate which one is throwing the error. So my question is:

Can anyone explain why React Native doesn't indicate the line number in this scenario? Is this an inherent property of how React Native works and it will always be impossible to identify the given line (if so, please explain why in as much detail as possible)? Or is there a way I can build my app differently in order to show the line numbers of errors?

Thanks!

enter image description here

2 Answers

Answer is NO for most cases.

The screen you shared here is of very little use for knowing where error is coming from.

You can use react native debugger to get more info on state/props changes or any exceptions. Stack trace also will not be of much help. You can write your own global error handling function for dev environment. Also remember not all error are JS ones, some are thrown by native modules also.

You can also set breakpoints and do runtime debugging using sources tab or you can blackbox the whole script, whatever is suitable. Debugging is one of the major drawbacks of React Native

The answer may be a Yes with a tool called Rollbar:

enter image description here

I do not mean to promote any tool, but, this one seems to be free thus can be adopted by the community. It does catch the line numbers for errors as well!

Related