-
Notifications
You must be signed in to change notification settings - Fork 53
Feature add error message for incorrect decorators #180
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
Feature add error message for incorrect decorators #180
Conversation
R/register.R
Outdated
|
|
||
| out <- decorations[decorations$decoration == tag, ] | ||
|
|
||
| if(any(!decorations$decoration %in% c("cpp11::register", "cpp11::init"))) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe store the result in a variable to make this easier to read?
e.g.
bad_decorations <- !decorations$decoration %in% c("cpp11::register", "cpp11::init")
if (any(bad_decorations)) { # etc..There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure!
R/register.R
Outdated
| out <- decorations[decorations$decoration == tag, ] | ||
|
|
||
| if(any(!decorations$decoration %in% c("cpp11::register", "cpp11::init"))) { | ||
| lines <- decorations$line[which(!decorations$decoration %in% c("cpp11::register", "cpp11::init"))] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The which() is unnecessary here, you can just index with the logical vector directly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
R/register.R
Outdated
| if(any(!decorations$decoration %in% c("cpp11::register", "cpp11::init"))) { | ||
| lines <- decorations$line[which(!decorations$decoration %in% c("cpp11::register", "cpp11::init"))] | ||
| if(length(lines) > 1) { | ||
| stop(call. = FALSE, paste0("Can't capture cpp11 decorators on lines ", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe the error should be something like
cpp11 attributes must be either `cpp11::register` or `cpp11::init`:
- Invalid attribute [[cpp11::foobar]] on line 123 in file xyz.
- Invalid attribute [[cpp11::baz]] on line 456 in file abc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh that looks great!
Is the best way to make multi-line error messages by using a combination of paste() statements with sep = "\n" ? Or would this be a message() following by an empty stop() ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can actually use glue to do this a little more nicely, something like this (untested, might need tweaks)
bad_lines <- glue::glue_collapse(
glue::glue("- Invalid attribute `{names}` on line {line} in file '{file}'."),
"\n"
)
msg <- glue::glue("
cpp11 attributes must be either `cpp11::register` or `cpp11::init`:
{bad_lines}
")
stop(msg, call. = FALSE)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh nice!
|
I think maybe we should pull this check out into a separate |
|
fixes #127 |
First pass for adding this error message. Error message could prolly still be more informative but let me know what you think!