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

Comments

Projects
None yet
3 participants
@lionel-
Copy link
Member

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

This comment has been minimized.

Copy link
Member

commented Apr 12, 2018

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-

This comment has been minimized.

Copy link
Member Author

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-

This comment has been minimized.

Copy link
Member Author

commented Apr 19, 2018

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.