rstudio/rstudio — pull request #166 by jmcphers (2014-09-25 16:28:07+00:00)
Title: Break on Error: improve heuristics for locating the error origin

This change fixes a recently reported bug in which the wrong frame in the callstack is chosen as the source of the error.

Today, the Break on Error code presumes that the error is raised with `stop(...)`. In this situation, we don't want to show the frame for `stop` itself; we want to show the frame that invoked `stop`. RStudio uses a baked-in offset that correctly locates this frame.

However, primitive functions can raise an error *without* calling `stop`. In this situation, there are fewer frames on the stack between the error handler and the frame that we want to show, and the baked-in offset is wrong.

The fix is to presume that the function raising the error is the very last one before we reach error-handling code. Most of the time, this will be `stop`, and when it is, we'll go one frame further. (We'll now also deal more gracefully with `stopifnot`).