Skip to content

Commit b226799

Browse files
proposed fix for ambiguous error message
1 parent 429eabf commit b226799

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

R/expect-condition.R

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,8 +295,20 @@ cnd_matcher <- function(base_class,
295295
check_string(regexp, allow_null = TRUE, allow_na = TRUE, call = error_call)
296296

297297
if (is.null(regexp) && dots_n(...) > 0) {
298+
# pretty adversarial: expect_error(foo(), NULL, "error", 1)
299+
# TODO(R>=4.1.0): ...names()
300+
dots_names <- names(list(...))
301+
if (is.null(dots_names) {
302+
cli::cli_abort(
303+
"Found unnamed arguments in {.arg ...} to be passed to {.fn grepl}, but no {.arg regexp}",
304+
call = error_call
305+
)
306+
}
298307
cli::cli_abort(
299-
"Can't specify {.arg ...} without {.arg regexp}.",
308+
c("Found arguments in {.arg ...} to be passed to {.fn grepl}, but no {.arg regexp}",
309+
"*" = "First problematic argument:",
310+
"i" = dots_names[which(nzchar(dots_names))[1L]]
311+
),
300312
call = error_call
301313
)
302314
}

0 commit comments

Comments
 (0)