jupyter-xeus / xeus-r

Jupyter kernel for the R programming language
Other
41 stars 5 forks source link

error traceback #10

Closed romainfrancois closed 10 months ago

romainfrancois commented 10 months ago

Currently we only get the default R print of errors. The only benefit being that it's printed in stderr, i.e. in red background

image

But we could access more information if we set a globalCallingHandlers() something like:

> globalCallingHandlers(error = function(err){ assign(".Last.error", err, globalenv()); assign(".Last.trace", sys.calls(), globalenv()) })
> f <- function() g()
> g <- function() h()
> h <- function() stop("ouch")
> h()
Error in h() : ouch
> f()
Error in h() : ouch
> .Last.error
<simpleError in h(): ouch>
> .Last.trace
[[1]]
f()

[[2]]
function() g()

[[3]]
function() h()

[[4]]
function() stop("ouch")

[[5]]
.handleSimpleError(function(err){ assign(".Last.error", err, globalenv()); assign(".Last.trace", sys.calls(), globalenv()) }, 
    "ouch", base::quote(h()))

[[6]]
h(simpleError(msg, call))

probably propagated through publish_execution_error() :

        // You can also use this method for publishing errors to the client, if the code
        // failed to execute
        // publish_execution_error(error_name, error_value, error_traceback);
        publish_execution_error("TypeError", "123", {"!@#$", "*(*"});