thomasp85 / fiery

A flexible and lightweight web server
https://fiery.data-imaginist.com
Other
240 stars 12 forks source link

Stack trace reporting #34

Open cpsievert opened 6 years ago

cpsievert commented 6 years ago

It seems as though fiery/routr/reqres based apps don't currently have a mechanism for reporting trace stacks (of errors), which makes debugging complex applications difficult. Here's a minimal example of the information reported in a request error (BTW, any idea why the error is being reported twice?):

library(fiery)
library(routr)

app <- Fire$new()

route <- Route$new()
route$add_handler('get', '*', function(request, response, keys, ...) {
  response$type <- 'html'
  response$status <- 200L
  response$body <- '<h1>All your AI are belong to us</h1>'
  1 + "a"
  FALSE
})

router <- RouteStack$new()
router$add_route(route, "main")
app$attach(router)
app$ignite(showcase = TRUE)
Fire started at 127.0.0.1:8080
error: non-numeric argument to binary operator
error: non-numeric argument to binary operator

With shiny, if you run an app that is saved to disk, it reports the line at which the error occurs -- would it be possible to add something similar to the fiery/routr/reqres stack?

library(shiny)

ui <- fluidPage(
  plotOutput("p")
)

server <- function(input, output, ...) {

  output$p <- renderPlot({
    1+"a"
    qplot(1:10)
  })

}

shinyApp(ui, server)
runApp('test-app-shiny.R')
Listening on http://127.0.0.1:5017
Warning: Error in +: non-numeric argument to binary operator
  161: renderPlot [~/test-app-shiny.R#10]
  159: func
  119: drawPlot
  105: <reactive:plotObj>
   92: drawReactive
   79: origRenderFunc
   78: output$p
    1: runApp
thomasp85 commented 4 years ago

I don't think it is possible to get the same line-number reporting as shiny, as fiery code is not sourced in the same way... A better backtrace is important though, maybe with a logger_backtrace()