-
Notifications
You must be signed in to change notification settings - Fork 323
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
Better error messages for tag parsing failures #771
Conversation
Fixes r-lib#770 I tried to make the error messages extremely verbose by passing in information about the file name and section tag from where the error originated. This may be a little fragile, but it didn't break any existing tests. - Added unit test for as_html.tag_url - Made errors more verbose by changing stopifnot() to if-then with a descriptive stop message in multiple cases (e.g., as_html.tag_url, as_html.tag_eqn, etc) - Also trying to pass in information on the Section and File from which the error was thrown.
You shouldn't be passing them in If I can give you some concrete advice are you interested in finishing this PR off? |
R/rd-html.R
Outdated
@@ -100,7 +109,17 @@ as_html.tag_subsection <- function(x, ...) { | |||
|
|||
#' @export | |||
as_html.tag_eqn <- function(x, ..., mathjax = TRUE) { | |||
stopifnot(length(x) <= 2) | |||
if ( length(x) > 2 ) { | |||
dots <- list(...) |
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.
-
I think this should use
context_get("rdname")
to get the name of the input file. -
I don't think it's worth changing the interface of the function in order to add the section name, we can tackle that in the future.
-
Since you've repeated the same code multiple times, please extract it out into a function
Thanks for the tips! Here's what I will try to do: Input file name
Instead of passing Section name
I'll omit any use of Function
I'll merge all of the repeated code into a subfunction as best I can! |
passes all tests in testthat::test_file("tests/testthat/test-rd-html.R")
- Combines similar code into one function - Passes all 67 tests in testthat::test_file("tests/testthat/test-rd-html.R") - Note that the test uses a call to rlang::bind_env(), which helped me to make sure the function worked as desired. This may however have some side effects that I dont know about.
|
||
## Binding the rdname to the context environment allows | ||
# stop_on_bad_html_tag() to grab the filename via rlang | ||
rlang::env_bind(.env = context, rdname = "test-rd-html.R") |
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.
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 use scoped_file_context()
which was designed for this exact scenario 😄
I've made changes that should resolve the comments you've brought up. There are two outstanding issues:
|
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.
Looks like you've made good progress! I've made a few more comments.
|
||
## Binding the rdname to the context environment allows | ||
# stop_on_bad_html_tag() to grab the filename via rlang | ||
rlang::env_bind(.env = context, rdname = "test-rd-html.R") |
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 use scoped_file_context()
which was designed for this exact scenario 😄
) | ||
|
||
## Empty URLs throw errors | ||
expect_error( rd2html(x = "\\url{}") ) |
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 need to include a fragment of the error message to match on to ensure that you're finding the expected error.
@@ -185,7 +207,9 @@ as_html.tag_link <- function(x, ...) { | |||
|
|||
#' @export | |||
as_html.tag_linkS4class <- function(x, ...) { | |||
stopifnot(length(x) == 1) | |||
if ( length(x) != 1 ) { |
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.
Can you please remove the extra spaces inside the parens? (https://style.tidyverse.org/syntax.html#parentheses)
Yes, please do merge/rebase to resolve the merge conflict. Also note that I changed the PR title to be more informative (and as general rule, you should never include an issue number in the PR title) |
Great! Thanks for all the help - it's very instructive. I'll try to have this done this week, but feel free to ping me if it becomes urgent. |
This attempts to fix #770
Please take a look at the way I am wrangling and passing
file_name
andsection_name
through.This did not break any existing tests, but I think it's perhaps a little more fragile than I'd like. I'd be happy for suggestions - maybe it's a good idea to create a
wrangleSectionName()
function and add some tests to make sure theclass(x)[1]
works as intended?