Skip to content

Commit 296c703

Browse files
authored
Modify error message to show .x argument name for one or more inputs (#1217)
Closes #1151
1 parent 8b270f7 commit 296c703

File tree

8 files changed

+25
-26
lines changed

8 files changed

+25
-26
lines changed

R/map.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,10 +281,10 @@ with_indexed_errors <- function(
281281
if (i == 0L) {
282282
# Error happened before or after loop
283283
} else {
284-
message <- c(i = "In index: {i}.")
284+
message <- c(i = "In .x[[{i}]]")
285285
if (!is.null(names) && !is.na(names[[i]]) && names[[i]] != "") {
286286
name <- names[[i]]
287-
message <- c(message, i = "With name: {name}.")
287+
message <- paste(message, "/ .x${name}", sep = " ")
288288
} else {
289289
name <- NULL
290290
}

tests/testthat/_snaps/keep.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
keep(1:3, ~NA)
55
Condition
66
Error in `keep()`:
7-
i In index: 1.
7+
i In .x[[1]]
88
Caused by error:
99
! `.p()` must return a single `TRUE` or `FALSE`, not `NA`.
1010
Code
1111
discard(1:3, ~NA)
1212
Condition
1313
Error in `discard()`:
14-
i In index: 1.
14+
i In .x[[1]]
1515
Caused by error:
1616
! `.p()` must return a single `TRUE` or `FALSE`, not `NA`.
1717

tests/testthat/_snaps/map-depth.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
map_depth(x1, 6, length)
55
Condition
66
Error in `.fmap()`:
7-
i In index: 1.
7+
i In .x[[1]]
88
Caused by error in `.fmap()`:
9-
i In index: 1.
9+
i In .x[[1]]
1010
Caused by error in `.fmap()`:
11-
i In index: 1.
11+
i In .x[[1]]
1212
Caused by error in `map_depth()`:
1313
! List not deep enough
1414

@@ -26,7 +26,7 @@
2626
map_depth(x, 2, class)
2727
Condition
2828
Error in `.fmap()`:
29-
i In index: 1.
29+
i In .x[[1]]
3030
Caused by error in `map_depth()`:
3131
! List not deep enough
3232

@@ -36,11 +36,11 @@
3636
modify_depth(x1, 5, length)
3737
Condition
3838
Error in `map()`:
39-
i In index: 1.
39+
i In .x[[1]]
4040
Caused by error in `map()`:
41-
i In index: 1.
41+
i In .x[[1]]
4242
Caused by error in `map()`:
43-
i In index: 1.
43+
i In .x[[1]]
4444
Caused by error in `modify_depth()`:
4545
! List not deep enough
4646

@@ -58,11 +58,11 @@
5858
modify_depth(x, 5, `+`, 10L)
5959
Condition
6060
Error in `map()`:
61-
i In index: 1.
61+
i In .x[[1]]
6262
Caused by error in `map()`:
63-
i In index: 1.
63+
i In .x[[1]]
6464
Caused by error in `map()`:
65-
i In index: 1.
65+
i In .x[[1]]
6666
Caused by error in `modify_depth()`:
6767
! List not deep enough
6868

tests/testthat/_snaps/map-if-at.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
map_if(1:3, ~NA, ~"foo")
55
Condition
66
Error in `map_if()`:
7-
i In index: 1.
7+
i In .x[[1]]
88
Caused by error:
99
! `.p()` must return a single `TRUE` or `FALSE`, not `NA`.
1010

tests/testthat/_snaps/map.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,21 @@
2020
map_int(1:3, ~ fail_at_3(.x, 2:1))
2121
Condition
2222
Error in `map_int()`:
23-
i In index: 3.
23+
i In .x[[3]]
2424
Caused by error:
2525
! Result must be length 1, not 2.
2626
Code
2727
map_int(1:3, ~ fail_at_3(.x, "x"))
2828
Condition
2929
Error in `map_int()`:
30-
i In index: 3.
30+
i In .x[[3]]
3131
Caused by error:
3232
! Can't coerce from a string to an integer.
3333
Code
3434
map(1:3, ~ fail_at_3(.x, stop("Doesn't work")))
3535
Condition
3636
Error in `map()`:
37-
i In index: 3.
37+
i In .x[[3]]
3838
Caused by error in `fail_at_3()`:
3939
! Doesn't work
4040

@@ -44,15 +44,14 @@
4444
map_int(c(a = 1, b = 2, c = 3), ~ fail_at_3(.x, stop("Error")))
4545
Condition
4646
Error in `map_int()`:
47-
i In index: 3.
48-
i With name: c.
47+
! In .x[[3]] / .x$c
4948
Caused by error in `fail_at_3()`:
5049
! Error
5150
Code
5251
map_int(c(a = 1, b = 2, 3), ~ fail_at_3(.x, stop("Error")))
5352
Condition
5453
Error in `map_int()`:
55-
i In index: 3.
54+
i In .x[[3]]
5655
Caused by error in `fail_at_3()`:
5756
! Error
5857

tests/testthat/_snaps/map2.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
map2_int(1, 1, ~"x")
55
Condition
66
Error in `map2_int()`:
7-
i In index: 1.
7+
i In .x[[1]]
88
Caused by error:
99
! Can't coerce from a string to an integer.
1010
Code
1111
map2_int(1, 1, ~ 1:2)
1212
Condition
1313
Error in `map2_int()`:
14-
i In index: 1.
14+
i In .x[[1]]
1515
Caused by error:
1616
! Result must be length 1, not 2.
1717
Code

tests/testthat/_snaps/modify.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@
8686
modify_if(list(1, 2), ~NA, ~"foo")
8787
Condition
8888
Error in `modify_if()`:
89-
i In index: 1.
89+
i In .x[[1]]
9090
Caused by error:
9191
! `.p()` must return a single `TRUE` or `FALSE`, not `NA`.
9292

tests/testthat/_snaps/pmap.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
pmap_int(list(1), ~"x")
55
Condition
66
Error in `pmap_int()`:
7-
i In index: 1.
7+
i In .x[[1]]
88
Caused by error:
99
! Can't coerce from a string to an integer.
1010
Code
1111
pmap_int(list(1), ~ 1:2)
1212
Condition
1313
Error in `pmap_int()`:
14-
i In index: 1.
14+
i In .x[[1]]
1515
Caused by error:
1616
! Result must be length 1, not 2.
1717
Code

0 commit comments

Comments
 (0)