From 370cd49fbfb12254aca169eccb1e3478a275ebfe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kirill=20M=C3=BCller?= Date: Thu, 15 Aug 2024 19:28:49 +0200 Subject: [PATCH] Explicit error message --- R/list-transpose.R | 13 +++++++++---- tests/testthat/_snaps/list-transpose.md | 4 ++-- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/R/list-transpose.R b/R/list-transpose.R index 390101cb..5abcbaec 100644 --- a/R/list-transpose.R +++ b/R/list-transpose.R @@ -75,10 +75,15 @@ list_transpose <- function(x, if (length(x) == 0) { template <- integer() } else if (is.null(template)) { - template <- reduce( - map(x, vec_index), - vec_set_union, - error_call = caller_env() + indexes <- map(x, vec_index) + try_fetch( + template <- reduce(indexes, vec_set_union), + vctrs_error_ptype2 = function(e) { + cli::cli_abort( + "Can't combine named and unnamed vectors.", + arg = template + ) + } ) } diff --git a/tests/testthat/_snaps/list-transpose.md b/tests/testthat/_snaps/list-transpose.md index 92809b55..31d33924 100644 --- a/tests/testthat/_snaps/list-transpose.md +++ b/tests/testthat/_snaps/list-transpose.md @@ -69,6 +69,6 @@ Code list_transpose(list(x = list(a = 1, b = 2), y = list(3, 4))) Condition - Error: - ! Can't combine `x` and `y` . + Error in `handlers[[1L]]()`: + ! Can't combine named and unnamed vectors.