Skip to content

Commit 433fe78

Browse files
committed
Simplify result rethrowing
1 parent 4e50c58 commit 433fe78

File tree

1 file changed

+31
-39
lines changed

1 file changed

+31
-39
lines changed

R/subscript-loc.R

Lines changed: 31 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -199,15 +199,8 @@ vec_as_location2_result <- function(i,
199199
arg = arg,
200200
call = call
201201
)
202-
203202
if (!is_null(result$err)) {
204-
parent <- result$err
205-
return(result(err = new_error_location2_type(
206-
i = i,
207-
subscript_arg = arg,
208-
body = parent$body,
209-
call = call
210-
)))
203+
return(result)
211204
}
212205

213206
# Locations must be size 1, can't be NA, and must be positive
@@ -284,6 +277,36 @@ vec_as_location2_result <- function(i,
284277
}
285278
}
286279

280+
new_error_location2_type <- function(i,
281+
...,
282+
class = NULL) {
283+
new_error_subscript2_type(
284+
class = class,
285+
i = i,
286+
numeric = "cast",
287+
character = "cast",
288+
...
289+
)
290+
}
291+
292+
cnd_bullets_location2_need_scalar <- function(cnd, ...) {
293+
cnd$subscript_arg <- append_arg("Subscript", cnd$subscript_arg)
294+
format_error_bullets(c(
295+
x = glue::glue_data(cnd, "{subscript_arg} must be size 1, not {length(i)}.")
296+
))
297+
}
298+
cnd_bullets_location2_need_present <- function(cnd, ...) {
299+
cnd$subscript_arg <- append_arg("Subscript", cnd$subscript_arg)
300+
format_error_bullets(c(
301+
x = glue::glue_data(cnd, "{subscript_arg} must be a location, not {obj_type_friendly(i)}.")
302+
))
303+
}
304+
cnd_bullets_location2_need_positive <- function(cnd, ...) {
305+
cnd$subscript_arg <- append_arg("Subscript", cnd$subscript_arg)
306+
format_error_bullets(c(
307+
x = glue::glue_data(cnd, "{subscript_arg} must be a positive location, not {i}.")
308+
))
309+
}
287310

288311
stop_location_negative_missing <- function(i, ..., call = caller_env()) {
289312
cnd <- new_chained_error_subscript_type(
@@ -336,37 +359,6 @@ cnd_body_vctrs_error_location_negative_positive <- function(cnd, ...) {
336359
))
337360
}
338361

339-
340-
new_error_location2_type <- function(i,
341-
...,
342-
class = NULL) {
343-
new_error_subscript2_type(
344-
class = class,
345-
i = i,
346-
numeric = "cast",
347-
character = "cast",
348-
...
349-
)
350-
}
351-
cnd_bullets_location2_need_scalar <- function(cnd, ...) {
352-
cnd$subscript_arg <- append_arg("Subscript", cnd$subscript_arg)
353-
format_error_bullets(c(
354-
x = glue::glue_data(cnd, "{subscript_arg} must be size 1, not {length(i)}.")
355-
))
356-
}
357-
cnd_bullets_location2_need_present <- function(cnd, ...) {
358-
cnd$subscript_arg <- append_arg("Subscript", cnd$subscript_arg)
359-
format_error_bullets(c(
360-
x = glue::glue_data(cnd, "{subscript_arg} must be a location, not {obj_type_friendly(i)}.")
361-
))
362-
}
363-
cnd_bullets_location2_need_positive <- function(cnd, ...) {
364-
cnd$subscript_arg <- append_arg("Subscript", cnd$subscript_arg)
365-
format_error_bullets(c(
366-
x = glue::glue_data(cnd, "{subscript_arg} must be a positive location, not {i}.")
367-
))
368-
}
369-
370362
stop_location_negative <- function(i, ..., call = caller_env()) {
371363
cnd <- new_chained_error_subscript_type(
372364
i,

0 commit comments

Comments
 (0)