-
Notifications
You must be signed in to change notification settings - Fork 38
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
bug(?): validators must return NULL #454
Comments
That's because they can return a string to more easily create an error. |
The pattern that's easiest is to use validate_factor <- function(self) {
c(
if (typeof(self) != "integer")
"Underlying data must be an <integer>",
if (!is.character(attr(self, "levels", TRUE)))
"attr(, 'levels') must be a <character>",
{ rng <- range(unclass(self), 0L); NULL },
if (rng[1] < 0L)
"Underlying data must be all positive",
if (rng[2] > length(attr(self, "levels", TRUE)))
"Not enough 'levels' for underlying data"
)
} (Side-note: technically, the check on the validator returned value is for Also, IMO, the pattern of evaluating an expression "in-line" in the my_validator <- function(self) {
.things_wrong <- character()
invalid <- function(...) .things_wrong <<- c(.things_wrong, paste0(...))
if(check1(self))
invalid("thing1")
if(check2(self))
invalid("thing2")
if(check3(self))
invalid("thing3")
.things_wrong
} |
For posterity this comes from:
Perhaps there can be checks or a more informative error message when the validator returns an unexpected object. I know I will forget about this in a month or so and find this issue. The current behavior works to the letter of the law but it does feel like the validator has to be coaxed |
I agree, we should emit a better error message if the validator returns something other than |
I have observed that validators must return
NULL
otherwise the validators error out. I cannot reason as to why this is. Is this intended behavior? Should the validators always returnself
?The text was updated successfully, but these errors were encountered: