diff --git a/R/list-transpose.R b/R/list-transpose.R index 5abcbaec..cd9e737d 100644 --- a/R/list-transpose.R +++ b/R/list-transpose.R @@ -76,12 +76,14 @@ list_transpose <- function(x, template <- integer() } else if (is.null(template)) { indexes <- map(x, vec_index) - try_fetch( + call <- current_env() + withCallingHandlers( template <- reduce(indexes, vec_set_union), vctrs_error_ptype2 = function(e) { cli::cli_abort( "Can't combine named and unnamed vectors.", - arg = template + arg = template, + call = call ) } ) diff --git a/tests/testthat/_snaps/list-transpose.md b/tests/testthat/_snaps/list-transpose.md index 31d33924..36a7dd4d 100644 --- a/tests/testthat/_snaps/list-transpose.md +++ b/tests/testthat/_snaps/list-transpose.md @@ -67,8 +67,8 @@ # fail mixing named and unnamed vectors Code - list_transpose(list(x = list(a = 1, b = 2), y = list(3, 4))) + test_list_transpose() Condition - Error in `handlers[[1L]]()`: + Error in `list_transpose()`: ! Can't combine named and unnamed vectors. diff --git a/tests/testthat/test-list-transpose.R b/tests/testthat/test-list-transpose.R index 398e233a..91895abf 100644 --- a/tests/testthat/test-list-transpose.R +++ b/tests/testthat/test-list-transpose.R @@ -132,8 +132,11 @@ test_that("validates inputs", { }) test_that("fail mixing named and unnamed vectors", { - x <- list(list(a = 1, b = 2), list(a = 3, b = 4)) - expect_snapshot(error = TRUE, { + test_list_transpose <- function() { + x <- list(list(a = 1, b = 2), list(a = 3, b = 4)) list_transpose(list(x = list(a = 1, b = 2), y = list(3, 4))) + } + expect_snapshot(error = TRUE, { + test_list_transpose() }) })