Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow OnUnhandledError to be scoped to modules #4033

Open
carlganz opened this issue Apr 24, 2024 · 0 comments
Open

Allow OnUnhandledError to be scoped to modules #4033

carlganz opened this issue Apr 24, 2024 · 0 comments

Comments

@carlganz
Copy link
Contributor

Currently, any callback registered with OnUnhandledError will trigger regardless of where the error occurs or where the callback is registered.

library(shiny)

mod_ui <- function(id) {
  ns <- NS(id)
  uiOutput(ns("sess"))
}

mod_server <- function(input, output, session) {
  onUnhandledError(function(err) {
    # log the unhandled error
    print("inner handler")
  }, session = session)

  output$sess <- renderUI({
# comment this stop out to see how it works when error is outside module
    stop("error msg")
  })
}

# Define UI for application that draws a histogram
ui <- fluidPage(

  mod_ui("test")  ,  uiOutput("sess")
)

# Define server logic required to draw a histogram
server <- function(input, output, session) {
  
  onUnhandledError(function(err) {
    # log the unhandled error
    print("outer handlers")
  }, session = session)
    
callModule(mod_server, "test")
  
output$sess <- renderUI({
 stop("another error msg")
})

}

# Run the application 
shinyApp(ui = ui, server = server)

Regardless of whether the error takes place inside or outside the module both callbacks trigger.

Based on comment here it seems scoping the callbacks to modules would be possible with some updates to session_proxy.

My goal is to use this to create a wrapper of callModule that imitates purrr::safely but reactively so I can call a 3rd party module, and capture an error in the child reactive environment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant