Skip to content

Commit

Permalink
Simplify backtraces of warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
lionel- committed Sep 21, 2022
1 parent e5ee5be commit ac63abf
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 208 deletions.
4 changes: 1 addition & 3 deletions R/mutate.R
Original file line number Diff line number Diff line change
Expand Up @@ -267,9 +267,7 @@ mutate_cols <- function(.data, dots, 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))
w$trace <- trace_back(bottom = error_call)
}
new <- cnd_data(
cnd = w,
Expand Down
270 changes: 65 additions & 205 deletions tests/testthat/_snaps/conditions.md
Original file line number Diff line number Diff line change
Expand Up @@ -248,17 +248,9 @@
! msg
---
Backtrace:
x
1. +-dplyr::mutate(df, x = f())
2. +-dplyr:::mutate.data.frame(df, x = f())
3. | \-dplyr:::mutate_cols(.data, dplyr_quosures(...))
4. | +-base::withCallingHandlers(...)
5. | \-(function() {...
6. | \-dplyr:::mutate_col(dots[[i]], .data, mask, new_columns)
7. | \-mask$eval_all_mutate(quo)
8. | \-dplyr (local) eval()
9. \-dplyr (local) f()
10. \-base::warning("msg")
x
1. +-dplyr::mutate(df, x = f())
2. \-dplyr:::mutate.data.frame(df, x = f())

---
Expand All @@ -285,17 +277,9 @@
! msg
---
Backtrace:
x
1. +-dplyr::mutate(group_by(df, id), x = f())
2. +-dplyr:::mutate.data.frame(group_by(df, id), x = f())
3. | \-dplyr:::mutate_cols(.data, dplyr_quosures(...))
4. | +-base::withCallingHandlers(...)
5. | \-(function() {...
6. | \-dplyr:::mutate_col(dots[[i]], .data, mask, new_columns)
7. | \-mask$eval_all_mutate(quo)
8. | \-dplyr (local) eval()
9. \-dplyr (local) f()
10. \-base::warning("msg")
x
1. +-dplyr::mutate(group_by(df, id), x = f())
2. \-dplyr:::mutate.data.frame(group_by(df, id), x = f())
[[2]]
<warning/rlang_warning>
Expand All @@ -305,17 +289,9 @@
! msg
---
Backtrace:
x
1. +-dplyr::mutate(group_by(df, id), x = f())
2. +-dplyr:::mutate.data.frame(group_by(df, id), x = f())
3. | \-dplyr:::mutate_cols(.data, dplyr_quosures(...))
4. | +-base::withCallingHandlers(...)
5. | \-(function() {...
6. | \-dplyr:::mutate_col(dots[[i]], .data, mask, new_columns)
7. | \-mask$eval_all_mutate(quo)
8. | \-dplyr (local) eval()
9. \-dplyr (local) f()
10. \-base::warning("msg")
x
1. +-dplyr::mutate(group_by(df, id), x = f())
2. \-dplyr:::mutate.data.frame(group_by(df, id), x = f())

---
Expand All @@ -342,17 +318,9 @@
! msg
---
Backtrace:
x
1. +-dplyr::mutate(rowwise(df), x = f())
2. +-dplyr:::mutate.data.frame(rowwise(df), x = f())
3. | \-dplyr:::mutate_cols(.data, dplyr_quosures(...))
4. | +-base::withCallingHandlers(...)
5. | \-(function() {...
6. | \-dplyr:::mutate_col(dots[[i]], .data, mask, new_columns)
7. | \-mask$eval_all_mutate(quo)
8. | \-dplyr (local) eval()
9. \-dplyr (local) f()
10. \-base::warning("msg")
x
1. +-dplyr::mutate(rowwise(df), x = f())
2. \-dplyr:::mutate.data.frame(rowwise(df), x = f())
[[2]]
<warning/rlang_warning>
Expand All @@ -362,17 +330,9 @@
! msg
---
Backtrace:
x
1. +-dplyr::mutate(rowwise(df), x = f())
2. +-dplyr:::mutate.data.frame(rowwise(df), x = f())
3. | \-dplyr:::mutate_cols(.data, dplyr_quosures(...))
4. | +-base::withCallingHandlers(...)
5. | \-(function() {...
6. | \-dplyr:::mutate_col(dots[[i]], .data, mask, new_columns)
7. | \-mask$eval_all_mutate(quo)
8. | \-dplyr (local) eval()
9. \-dplyr (local) f()
10. \-base::warning("msg")
x
1. +-dplyr::mutate(rowwise(df), x = f())
2. \-dplyr:::mutate.data.frame(rowwise(df), x = f())

---
Expand Down Expand Up @@ -412,23 +372,13 @@
! msg
---
Backtrace:
x
1. +-dplyr::mutate(...)
2. +-dplyr::group_by(...)
3. +-dplyr::mutate(rowwise(group_by(df, g = f():n())), x = f())
4. +-dplyr::rowwise(group_by(df, g = f():n()))
5. +-dplyr::group_by(df, g = f():n())
6. +-dplyr:::group_by.data.frame(df, g = f():n())
7. | \-dplyr::group_by_prepare(.data, ..., .add = .add, error_call = current_env())
8. | \-dplyr:::add_computed_columns(.data, new_groups, error_call = error_call)
9. | \-dplyr:::mutate_cols(...)
10. | +-base::withCallingHandlers(...)
11. | \-(function() {...
12. | \-dplyr:::mutate_col(dots[[i]], .data, mask, new_columns)
13. | \-mask$eval_all_mutate(quo)
14. | \-dplyr (local) eval()
15. \-dplyr (local) f()
16. \-base::warning("msg")
x
1. +-dplyr::mutate(...)
2. +-dplyr::group_by(...)
3. +-dplyr::mutate(rowwise(group_by(df, g = f():n())), x = f())
4. +-dplyr::rowwise(group_by(df, g = f():n()))
5. +-dplyr::group_by(df, g = f():n())
6. \-dplyr:::group_by.data.frame(df, g = f():n())
[[2]]
<warning/rlang_warning>
Expand All @@ -438,19 +388,11 @@
! msg
---
Backtrace:
x
1. +-dplyr::mutate(...)
2. +-dplyr::group_by(...)
3. +-dplyr::mutate(rowwise(group_by(df, g = f():n())), x = f())
4. +-dplyr:::mutate.data.frame(...)
5. | \-dplyr:::mutate_cols(.data, dplyr_quosures(...))
6. | +-base::withCallingHandlers(...)
7. | \-(function() {...
8. | \-dplyr:::mutate_col(dots[[i]], .data, mask, new_columns)
9. | \-mask$eval_all_mutate(quo)
10. | \-dplyr (local) eval()
11. \-dplyr (local) f()
12. \-base::warning("msg")
x
1. +-dplyr::mutate(...)
2. +-dplyr::group_by(...)
3. +-dplyr::mutate(rowwise(group_by(df, g = f():n())), x = f())
4. \-dplyr:::mutate.data.frame(...)
[[3]]
<warning/rlang_warning>
Expand All @@ -460,19 +402,11 @@
! msg
---
Backtrace:
x
1. +-dplyr::mutate(...)
2. +-dplyr::group_by(...)
3. +-dplyr::mutate(rowwise(group_by(df, g = f():n())), x = f())
4. +-dplyr:::mutate.data.frame(...)
5. | \-dplyr:::mutate_cols(.data, dplyr_quosures(...))
6. | +-base::withCallingHandlers(...)
7. | \-(function() {...
8. | \-dplyr:::mutate_col(dots[[i]], .data, mask, new_columns)
9. | \-mask$eval_all_mutate(quo)
10. | \-dplyr (local) eval()
11. \-dplyr (local) f()
12. \-base::warning("msg")
x
1. +-dplyr::mutate(...)
2. +-dplyr::group_by(...)
3. +-dplyr::mutate(rowwise(group_by(df, g = f():n())), x = f())
4. \-dplyr:::mutate.data.frame(...)
[[4]]
<warning/rlang_warning>
Expand All @@ -482,17 +416,9 @@
! msg
---
Backtrace:
x
1. +-dplyr::mutate(...)
2. +-dplyr:::mutate.data.frame(...)
3. | \-dplyr:::mutate_cols(.data, dplyr_quosures(...))
4. | +-base::withCallingHandlers(...)
5. | \-(function() {...
6. | \-dplyr:::mutate_col(dots[[i]], .data, mask, new_columns)
7. | \-mask$eval_all_mutate(quo)
8. | \-dplyr (local) eval()
9. \-dplyr (local) f()
10. \-base::warning("msg")
x
1. +-dplyr::mutate(...)
2. \-dplyr:::mutate.data.frame(...)
[[5]]
<warning/rlang_warning>
Expand All @@ -502,17 +428,9 @@
! msg
---
Backtrace:
x
1. +-dplyr::mutate(...)
2. +-dplyr:::mutate.data.frame(...)
3. | \-dplyr:::mutate_cols(.data, dplyr_quosures(...))
4. | +-base::withCallingHandlers(...)
5. | \-(function() {...
6. | \-dplyr:::mutate_col(dots[[i]], .data, mask, new_columns)
7. | \-mask$eval_all_mutate(quo)
8. | \-dplyr (local) eval()
9. \-dplyr (local) f()
10. \-base::warning("msg")
x
1. +-dplyr::mutate(...)
2. \-dplyr:::mutate.data.frame(...)

---
Expand Down Expand Up @@ -546,17 +464,9 @@
! msg
---
Backtrace:
x
1. +-dplyr::mutate(rowwise(df), x = f())
2. +-dplyr:::mutate.data.frame(rowwise(df), x = f())
3. | \-dplyr:::mutate_cols(.data, dplyr_quosures(...))
4. | +-base::withCallingHandlers(...)
5. | \-(function() {...
6. | \-dplyr:::mutate_col(dots[[i]], .data, mask, new_columns)
7. | \-mask$eval_all_mutate(quo)
8. | \-dplyr (local) eval()
9. \-dplyr (local) f()
10. \-base::warning("msg")
x
1. +-dplyr::mutate(rowwise(df), x = f())
2. \-dplyr:::mutate.data.frame(rowwise(df), x = f())
Message
... with 1 more warning.
Expand Down Expand Up @@ -597,17 +507,9 @@
! msg
---
Backtrace:
x
1. +-dplyr::mutate(rowwise(df), x = f())
2. +-dplyr:::mutate.data.frame(rowwise(df), x = f())
3. | \-dplyr:::mutate_cols(.data, dplyr_quosures(...))
4. | +-base::withCallingHandlers(...)
5. | \-(function() {...
6. | \-dplyr:::mutate_col(dots[[i]], .data, mask, new_columns)
7. | \-mask$eval_all_mutate(quo)
8. | \-dplyr (local) eval()
9. \-dplyr (local) f()
10. \-base::warning("msg")
x
1. +-dplyr::mutate(rowwise(df), x = f())
2. \-dplyr:::mutate.data.frame(rowwise(df), x = f())
Message
... with 4 more warnings.
Expand Down Expand Up @@ -649,24 +551,12 @@
! foo
---
Backtrace:
x
1. +-dplyr (local) foo()
2. | \-dplyr (local) bar()
3. | +-dplyr::mutate(group_by(df, x = f(1):n()), x = f(1, base = FALSE))
4. | +-dplyr::group_by(df, x = f(1):n())
5. | \-dplyr:::group_by.data.frame(df, x = f(1):n())
6. | \-dplyr::group_by_prepare(.data, ..., .add = .add, error_call = current_env())
7. | \-dplyr:::add_computed_columns(.data, new_groups, error_call = error_call)
8. | \-dplyr:::mutate_cols(...)
9. | +-base::withCallingHandlers(...)
10. | \-(function() {...
11. | \-dplyr:::mutate_col(dots[[i]], .data, mask, new_columns)
12. | \-mask$eval_all_mutate(quo)
13. | \-dplyr (local) eval()
14. \-dplyr (local) f(1)
15. \-dplyr (local) g(...)
16. \-dplyr (local) h(...)
17. \-base::warning("foo")
x
1. \-dplyr (local) foo()
2. \-dplyr (local) bar()
3. +-dplyr::mutate(group_by(df, x = f(1):n()), x = f(1, base = FALSE))
4. +-dplyr::group_by(df, x = f(1):n())
5. \-dplyr:::group_by.data.frame(df, x = f(1):n())
[[2]]
<warning/rlang_warning>
Expand All @@ -676,21 +566,11 @@
! foo
---
Backtrace:
x
1. +-dplyr (local) foo()
2. | \-dplyr (local) bar()
3. | +-dplyr::mutate(group_by(df, x = f(1):n()), x = f(1, base = FALSE))
4. | \-dplyr:::mutate.data.frame(...)
5. | \-dplyr:::mutate_cols(.data, dplyr_quosures(...))
6. | +-base::withCallingHandlers(...)
7. | \-(function() {...
8. | \-dplyr:::mutate_col(dots[[i]], .data, mask, new_columns)
9. | \-mask$eval_all_mutate(quo)
10. | \-dplyr (local) eval()
11. \-dplyr (local) f(1, base = FALSE)
12. \-dplyr (local) g(...)
13. \-dplyr (local) h(...)
14. \-rlang::warn("foo")
x
1. \-dplyr (local) foo()
2. \-dplyr (local) bar()
3. +-dplyr::mutate(group_by(df, x = f(1):n()), x = f(1, base = FALSE))
4. \-dplyr:::mutate.data.frame(...)
[[3]]
<warning/rlang_warning>
Expand All @@ -700,21 +580,11 @@
! foo
---
Backtrace:
x
1. +-dplyr (local) foo()
2. | \-dplyr (local) bar()
3. | +-dplyr::mutate(group_by(df, x = f(1):n()), x = f(1, base = FALSE))
4. | \-dplyr:::mutate.data.frame(...)
5. | \-dplyr:::mutate_cols(.data, dplyr_quosures(...))
6. | +-base::withCallingHandlers(...)
7. | \-(function() {...
8. | \-dplyr:::mutate_col(dots[[i]], .data, mask, new_columns)
9. | \-mask$eval_all_mutate(quo)
10. | \-dplyr (local) eval()
11. \-dplyr (local) f(1, base = FALSE)
12. \-dplyr (local) g(...)
13. \-dplyr (local) h(...)
14. \-rlang::warn("foo")
x
1. \-dplyr (local) foo()
2. \-dplyr (local) bar()
3. +-dplyr::mutate(group_by(df, x = f(1):n()), x = f(1, base = FALSE))
4. \-dplyr:::mutate.data.frame(...)
[[4]]
<warning/rlang_warning>
Expand All @@ -724,20 +594,10 @@
! foo
---
Backtrace:
x
1. +-dplyr (local) foo()
2. | \-dplyr (local) bar()
3. | +-dplyr::mutate(group_by(df, x = f(1):n()), x = f(1, base = FALSE))
4. | \-dplyr:::mutate.data.frame(...)
5. | \-dplyr:::mutate_cols(.data, dplyr_quosures(...))
6. | +-base::withCallingHandlers(...)
7. | \-(function() {...
8. | \-dplyr:::mutate_col(dots[[i]], .data, mask, new_columns)
9. | \-mask$eval_all_mutate(quo)
10. | \-dplyr (local) eval()
11. \-dplyr (local) f(1, base = FALSE)
12. \-dplyr (local) g(...)
13. \-dplyr (local) h(...)
14. \-rlang::warn("foo")
x
1. \-dplyr (local) foo()
2. \-dplyr (local) bar()
3. +-dplyr::mutate(group_by(df, x = f(1):n()), x = f(1, base = FALSE))
4. \-dplyr:::mutate.data.frame(...)

0 comments on commit ac63abf

Please sign in to comment.