Reputation: 723
When catching an error, I want to get with the stack trace the actual code of the line that triggered the error. Given that I have the path to the file and the line number throwing the error, what's the best way to also get the actual code of that line?
Upvotes: 3
Views: 328
Reputation: 630
Beyond the obvious of "looking it up in the file", there are a few things you can do to get it automatically. Checkout the Tracekit project on GitHub. For errors it captures, it will do an AJAX request for the script and find the relevant lines in the text.
Alternatively, if you're looking for a way to handle this automatically, you should consider a service like TrackJS that will capture all the relevant scripts and apply sourcemaps for you. I am one of the original developers and I've used it on many projects to fix bugs ridiculously fast :)
Upvotes: 2