Skip to content

Commit 165cb4f

Browse files
committed
Use standard subscript error header in OOB errors
1 parent ace0afd commit 165cb4f

File tree

8 files changed

+51
-69
lines changed

8 files changed

+51
-69
lines changed

NAMESPACE

-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,6 @@ S3method(cnd_header,vctrs_error_names_cannot_be_dot_dot)
111111
S3method(cnd_header,vctrs_error_names_cannot_be_empty)
112112
S3method(cnd_header,vctrs_error_names_must_be_unique)
113113
S3method(cnd_header,vctrs_error_subscript)
114-
S3method(cnd_header,vctrs_error_subscript_oob)
115114
S3method(diff,vctrs_vctr)
116115
S3method(duplicated,vctrs_sclr)
117116
S3method(duplicated,vctrs_vctr)

R/subscript-loc.R

-17
Original file line numberDiff line numberDiff line change
@@ -487,23 +487,6 @@ stop_subscript_oob <- function(i,
487487
)
488488
}
489489

490-
#' @export
491-
cnd_header.vctrs_error_subscript_oob <- function(cnd, ...) {
492-
if (cnd_subscript_oob_non_consecutive(cnd)) {
493-
return(cnd_header_vctrs_error_subscript_oob_non_consecutive(cnd, ...))
494-
}
495-
496-
elt <- cnd_subscript_element(cnd)
497-
action <- cnd_subscript_action(cnd)
498-
type <- cnd_subscript_type(cnd)
499-
500-
if (action %in% c("rename", "relocate") || type == "character") {
501-
glue::glue("Can't {action} {elt[[2]]} that don't exist.")
502-
} else {
503-
glue::glue("Can't {action} {elt[[2]]} past the end.")
504-
}
505-
}
506-
507490
#' @export
508491
cnd_body.vctrs_error_subscript_oob <- function(cnd, ...) {
509492
switch(cnd_subscript_type(cnd),

tests/testthat/_snaps/conditions.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -22,23 +22,23 @@
2222
Output
2323
<error/vctrs_error_subscript_oob>
2424
Error in `vec_slice()`:
25-
! Can't subset elements that don't exist.
25+
! Can't subset elements.
2626
x Element `foo` doesn't exist.
2727
Code
2828
(expect_error(with_subscript_data(vec_slice(set_names(letters), "foo"), quote(
2929
foo)), class = "vctrs_error_subscript_oob"))
3030
Output
3131
<error/vctrs_error_subscript_oob>
3232
Error in `vec_slice()`:
33-
! Can't subset elements that don't exist.
33+
! Can't subset elements with `foo`.
3434
x Element `foo` doesn't exist.
3535
Code
3636
(expect_error(with_subscript_data(vec_slice(set_names(letters), "foo"), quote(
3737
foo(bar))), class = "vctrs_error_subscript_oob"))
3838
Output
3939
<error/vctrs_error_subscript_oob>
4040
Error in `vec_slice()`:
41-
! Can't subset elements that don't exist.
41+
! Can't subset elements with `foo(bar)`.
4242
x Element `foo` doesn't exist.
4343

4444
# scalar type errors are informative

tests/testthat/_snaps/error-call.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@
207207
Output
208208
<error/vctrs_error_subscript_oob>
209209
Error in `my_function()`:
210-
! Can't subset elements past the end.
210+
! Can't subset elements with `10`.
211211
x Location must be less than or equal to 2, not 10.
212212
i There are only 2 elements.
213213

tests/testthat/_snaps/slice-assign.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
Output
3838
<error/vctrs_error_subscript_oob>
3939
Error:
40-
! Can't assign to elements past the end.
40+
! Can't assign elements.
4141
x Location must be less than or equal to 3, not 5.
4242
i There are only 3 elements.
4343
Code
@@ -52,7 +52,7 @@
5252
Output
5353
<error/vctrs_error_subscript_oob>
5454
Error:
55-
! Can't negate elements past the end.
55+
! Can't negate elements.
5656
x Location must be less than or equal to 26, not 100.
5757
i There are only 26 elements.
5858
Code
@@ -61,7 +61,7 @@
6161
Output
6262
<error/vctrs_error_subscript_oob>
6363
Error:
64-
! Can't assign to elements that don't exist.
64+
! Can't assign elements.
6565
x Element `foo` doesn't exist.
6666

6767
# must assign with proper negative locations

tests/testthat/_snaps/slice-chop.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@
227227
Output
228228
<error/vctrs_error_subscript_oob>
229229
Error:
230-
! Can't subset elements past the end.
230+
! Can't subset elements.
231231
x Location must be less than or equal to 2.
232232
i There are only 2 elements.
233233

tests/testthat/_snaps/slice.md

+7-7
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@
2323
Output
2424
<error/vctrs_error_subscript_oob>
2525
Error in `vec_slice()`:
26-
! Can't subset elements past the end.
26+
! Can't subset elements with `i`.
2727
x Location must be less than or equal to 2, not 3.
2828
i There are only 2 elements.
2929
Code
3030
(expect_error(vec_slice(1:2, -3L), class = "vctrs_error_subscript_oob"))
3131
Output
3232
<error/vctrs_error_subscript_oob>
3333
Error in `vec_slice()`:
34-
! Can't negate elements past the end.
34+
! Can't negate elements with `i`.
3535
x Location must be less than or equal to 2, not 3.
3636
i There are only 2 elements.
3737

@@ -79,7 +79,7 @@
7979
vec_slice(c(bar = 1), "foo")
8080
Condition
8181
Error in `vec_slice()`:
82-
! Can't subset elements that don't exist.
82+
! Can't subset elements with `i`.
8383
x Element `foo` doesn't exist.
8484

8585
---
@@ -88,7 +88,7 @@
8888
vec_slice(letters, c(100, 1000))
8989
Condition
9090
Error in `vec_slice()`:
91-
! Can't subset elements past the end.
91+
! Can't subset elements with `i`.
9292
x Locations must be less than or equal to 26.
9393
i There are only 26 elements.
9494

@@ -98,7 +98,7 @@
9898
vec_slice(letters, c(1, 100:103, 2, 104:110))
9999
Condition
100100
Error in `vec_slice()`:
101-
! Can't subset elements past the end.
101+
! Can't subset elements with `i`.
102102
x Locations must be less than or equal to 26.
103103
i There are only 26 elements.
104104

@@ -108,7 +108,7 @@
108108
vec_slice(set_names(letters), c("foo", "bar"))
109109
Condition
110110
Error in `vec_slice()`:
111-
! Can't subset elements that don't exist.
111+
! Can't subset elements with `i`.
112112
x Elements `foo` and `bar` don't exist.
113113

114114
---
@@ -117,7 +117,7 @@
117117
vec_slice(set_names(letters), toupper(letters))
118118
Condition
119119
Error in `vec_slice()`:
120-
! Can't subset elements that don't exist.
120+
! Can't subset elements with `i`.
121121
x Elements `A`, `B`, `C`, `D`, `E`, etc. don't exist.
122122

123123
# vec_init() validates `n`

0 commit comments

Comments
 (0)