Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve error message with missing arguments #743

Closed
lionel- opened this issue Apr 12, 2018 · 3 comments
Closed

Improve error message with missing arguments #743

lionel- opened this issue Apr 12, 2018 · 3 comments
Labels
bug an unexpected problem or unintended behavior expectation 🙀

Comments

@lionel-
Copy link
Member

lionel- commented Apr 12, 2018

expect_identical("foo")
#> Error in eval_bare(get_expr(quo), get_env(quo)) (from eval.R#97) : object '' not found
@jimhester
Copy link
Member

Any thoughts on a good way to handle this for all expectations?

I can do something like this, but the error message then is not much better.

diff --git a/R/expectation.R b/R/expectation.R
index 6dfd504..2f248c0 100644
--- a/R/expectation.R
+++ b/R/expectation.R
@@ -85,7 +85,9 @@ is.expectation <- function(x) inherits(x, "expectation")
 #' # variable name
 #' show_failure(expect_equal(f(!!i), !!(i * 10)))
 quasi_label <- function(quo, label = NULL) {
-  force(quo)
+  if (quo_is_missing(quo)) {
+    stop("`quo` is missing", call. = FALSE)
+  }

   list(
     val = eval_bare(get_expr(quo), get_env(quo)),
expect_identical("foo")
#> Error: quo is missing

Ideally this would be

`expected` is missing

I could hoist the quo_is_missing() check up to the expect_identical() body I guess, but then I would need to modify all of the other expectations in a similar way, which seems painful.

@lionel-
Copy link
Member Author

lionel- commented Apr 19, 2018

Unfortunately I think there's no great way around this other than adding an explicit argument to quasi_label() to pass the argument name.

@lionel-
Copy link
Member Author

lionel- commented Apr 19, 2018

Something like "Missing argument in expectation" would already be much better though.

@hadley hadley added bug an unexpected problem or unintended behavior expectation 🙀 labels Mar 28, 2019
@hadley hadley added this to the testthat 2.1.0 milestone Apr 1, 2019
@hadley hadley closed this as completed in 5db9225 Apr 1, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug an unexpected problem or unintended behavior expectation 🙀
Projects
None yet
Development

No branches or pull requests

3 participants