Skip to content

Commit a3c6b43

Browse files
committed
More error tidying
1 parent 029208a commit a3c6b43

File tree

3 files changed

+5
-34
lines changed

3 files changed

+5
-34
lines changed

R/expect-setequal.R

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -131,35 +131,6 @@ expect_in <- function(object, expected) {
131131

132132
# Helpers ----------------------------------------------------------------------
133133

134-
check_map_names <- function(
135-
x,
136-
error_arg = caller_arg(x),
137-
error_call = caller_env()
138-
) {
139-
nms <- names2(x)
140-
141-
if (anyDuplicated(nms)) {
142-
dups <- unique(nms[duplicated(nms)])
143-
cli::cli_abort(
144-
c(
145-
"All elements in {.arg {error_arg}} must have unique names.",
146-
x = "Duplicate names: {.str {dups}}"
147-
),
148-
call = error_call
149-
)
150-
}
151-
if (any(nms == "")) {
152-
empty <- which(nms == "")
153-
cli::cli_abort(
154-
c(
155-
"All elements in {.arg {error_arg}} must have names.",
156-
x = "Empty names at position{?s}: {empty}"
157-
),
158-
call = error_call
159-
)
160-
}
161-
}
162-
163134
check_vector <- function(
164135
x,
165136
error_arg = caller_arg(x),

R/mock2.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,18 +185,18 @@ local_bindings_rebind <- function(..., .env = .frame, .frame = caller_env()) {
185185
invisible()
186186
}
187187

188-
dev_package <- function() {
188+
dev_package <- function(call = caller_env()) {
189189
if (is_testing() && testing_package() != "") {
190190
testing_package()
191191
} else {
192192
loaded <- loadedNamespaces()
193193
is_dev <- map_lgl(loaded, function(x) !is.null(pkgload::dev_meta(x)))
194194
if (sum(is_dev) == 0) {
195-
cli::cli_abort("No packages loaded with pkgload")
195+
cli::cli_abort("No packages loaded with pkgload", call = call)
196196
} else if (sum(is_dev) == 1) {
197197
loaded[is_dev]
198198
} else {
199-
cli::cli_abort("Multiple packages loaded with pkgload")
199+
cli::cli_abort("Multiple packages loaded with pkgload", call = call)
200200
}
201201
}
202202
}

R/snapshot.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -408,13 +408,13 @@ local_snapshot_dir <- function(snap_names, .env = parent.frame()) {
408408
# if transform() wiped out the full message, don't indent, #1487
409409
indent <- function(x) if (length(x)) paste0(" ", x) else x
410410

411-
check_variant <- function(x) {
411+
check_variant <- function(x, call = caller_env()) {
412412
if (is.null(x)) {
413413
"_default"
414414
} else if (is_string(x)) {
415415
x
416416
} else {
417-
cli::cli_abort("If supplied, {.arg variant} must be a string.")
417+
cli::cli_abort("If supplied, {.arg variant} must be a string.", call = call)
418418
}
419419
}
420420

0 commit comments

Comments
 (0)