Skip to content

Commit

Permalink
Super conservatively wrap appendCallStackWithDupe in try/catch
Browse files Browse the repository at this point in the history
  • Loading branch information
jcheng5 committed Dec 5, 2024
1 parent a3d07a9 commit d4f144d
Showing 1 changed file with 24 additions and 9 deletions.
33 changes: 24 additions & 9 deletions R/conditions.R
Original file line number Diff line number Diff line change
Expand Up @@ -156,16 +156,31 @@ saveCallStackDigest <- function(callStack) {
# in the list. The list is deduplicated by digest; ideally the digests on the
# list are cached before calling this function (you will get a warning if not).
appendCallStackWithDedupe <- function(lst, x) {
digests <- vapply(lst, getCallStackDigest, character(1), warn = TRUE)
xdigest <- getCallStackDigest(x, warn = FALSE)
stopifnot(all(nzchar(digests)))
stopifnot(length(xdigest) == 1)
stopifnot(nzchar(xdigest))
if (xdigest %in% digests) {
return(lst)
} else {
tryCatch({
digests <- vapply(lst, getCallStackDigest, character(1), warn = TRUE)
xdigest <- getCallStackDigest(x, warn = FALSE)
stopifnot(all(nzchar(digests)))
stopifnot(length(xdigest) == 1)
stopifnot(nzchar(xdigest))
if (xdigest %in% digests) {
return(lst)
} else {
return(c(lst, list(x)))
}
}, error = function(e) {
# Hopefully will never hit this. I'm only putting this in to be suuuper
# conservative about not letting our new deep stack trace dedupe logic crash
# the Shiny app.
if (in_devmode()) {
printError(e, full = TRUE)
}
rlang::warn(
"Failed to deduplicate deep stack traces; appending anyway",
.frequency = "once",
.frequency_id = "deepstack-deduplication-warning"
)
return(c(lst, list(x)))
}
})
}

createStackTracePromiseDomain <- function() {
Expand Down

0 comments on commit d4f144d

Please sign in to comment.