3

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?

2
  • 3
    "Given that I have the path to the file and the line number throwing the error" Review .js file at given line number? Commented Jul 11, 2016 at 15:12
  • 2
    In some browers you can also click on the logged error and it'll take you to that line. Commented Jul 11, 2016 at 15:15

1 Answer 1

2

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 :)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.