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

Better error message for inifinite recursion situations #24

Open
jankowtf opened this issue Oct 28, 2014 · 0 comments
Open

Better error message for inifinite recursion situations #24

jankowtf opened this issue Oct 28, 2014 · 0 comments

Comments

@jankowtf
Copy link
Owner

Somehow I can't figure out how to "early exit" the withRestarts(tryCatch(...), ...) construct in setReactiveS3() or setShinyReactive():

              obj$.value <<- withRestarts(
                tryCatch(
                  {
                    out <- value()

                    ## Object state updates //
                    obj$.condition <- NULL
                    obj$.has_cached <- TRUE
                    obj$.needs_update <- FALSE

                    out 

                  ## For debugging/testing purposes 
#                     stop("Intentional update fail"),
                  },
                  warning = function(cond) {
                    invokeRestart("muffleWarning")
                  },
                  error = function(cond) {
                    invokeRestart("ReactiveUpdateFailed", cond = cond)
                  }
                ),
                muffleWarning = function(cond) {
                  message(cond)
                  invokeRestart("muffleWarning")
                },
                ReactiveUpdateFailed = function(cond) {     
                  signal <- FALSE
                  if (!cache) { 
                    if (grepl("object.*not found", conditionMessage(cond))) {
                      msg <- paste0("caching disabled -->", conditionMessage(cond))
                    } else if (grepl("evaluation nested too deeply.*infinite recursion", conditionMessage(cond))) {                
                      message(conditionMessage(cond))
                      msg <- "caching disabled --> infinite recursion"
                      signal <- TRUE
                    }
                  } else {
                    msg <- conditionMessage(cond)
                  }
                  cond <- conditionr::signalCondition(
                    call = substitute(
                      get(x= ID, envir = WHERE, inherits = FALSE),
                      list(ID = obj$.id, WHERE = obj$.where)
                    ),
                    condition = "AbortedReactiveUpdateWithError",
                    msg = c(
                      "Update failed",
                      Reason = msg,
                      ID = obj$.id,
                      UID = obj$.uid,
                      Location = capture.output(where)
                    ),
                    ns = "reactr",
                    type = "error",
                    signal = signal
                  )

                  ## Transfer condition //
                  obj$.condition <<- cond
                  NULL
                }
              )

Improve this

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

No branches or pull requests

1 participant