Skip to content

Commit

Permalink
Record backtraces for 5 first warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
lionel- committed Sep 8, 2022
1 parent 1625ae8 commit 37bd821
Show file tree
Hide file tree
Showing 6 changed files with 344 additions and 16 deletions.
9 changes: 7 additions & 2 deletions R/conditions.R
Original file line number Diff line number Diff line change
Expand Up @@ -265,13 +265,18 @@ new_dplyr_warning <- function(data) {
warning_cnd(
message = msg,
parent = data$cnd,
call = data$call
call = data$call,
trace = data$cnd$trace
)
}

#' @export
print.dplyr_last_warnings <- function(x, ...) {
print(unstructure(x), ...)
# Opt into experimental grayed out tree
local_options(
"rlang:::trace_display_tree" = TRUE
)
print(unstructure(x), ..., simplify = "none")

remaining <- attr(x, "remaining")
if (remaining) {
Expand Down
6 changes: 6 additions & 0 deletions R/mutate.R
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,12 @@ mutate_cols <- function(.data, dots, caller_env, error_call = caller_env()) {
)
},
warning = function(w) {
# Don't entrace more than 5 warnings because this is very costly
if (is_null(w$trace) && length(warnings) <= 5) {
# The frame skipping assumes a regular `base::warning()` stack.
# Also works with warnings emitted from C with `Rf_warning()`.
w$trace <- trace_back(bottom = sys.frame(-5))
}
new <- cnd_data(
cnd = w,
error_ctxt,
Expand Down
Loading

0 comments on commit 37bd821

Please sign in to comment.