-
Notifications
You must be signed in to change notification settings - Fork 73
Adding exception handling for invalid parse data. #139
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
Adding exception handling for invalid parse data. #139
Conversation
7293729
to
b50da33
Compare
The only thing that bothers me a bit is that the return value is just a message, not an error, but I think there is no way around it if we want to continue with other files, right? |
ee0aacf
to
02b8c79
Compare
02b8c79
to
79d1585
Compare
Codecov Report
@@ Coverage Diff @@
## master #139 +/- ##
==========================================
+ Coverage 87.46% 87.61% +0.15%
==========================================
Files 19 19
Lines 742 751 +9
==========================================
+ Hits 649 658 +9
Misses 93 93
Continue to review full report at Codecov.
|
79d1585
to
d0d87d7
Compare
R/transform.R
Outdated
#' @inheritParams make_transformer | ||
#' @return A logical value that indicates whether or not any file was changed is | ||
#' returned invisibly. If files were changed, the user is informed to | ||
#' carefully inspect the changes via a message sent to the console. | ||
transform_files <- function(files, transformers) { | ||
transform_files <- function(files, transformers, assert_code = TRUE) { |
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'm not sure we need a new argument here. Rather the behavior should always be reasonable if parsing fails. If necessary, we could change transform_lines_enc()
to account for this.
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.
Ok, so we can remove the argument then. I am not sure whether it makes sense to implement the error handling in transform_lines_enc()
since it has already a error handling but I don't know why it does only give a warning instead of an error.
library("styler")
style_text("a 3")
#> Error in parse(text = text, keep.source = TRUE): <text>:1:3: unexpected numeric constant
#> 1: a 3
#> ^
path <- tempfile(fileext = ".R")
writeLines("a 3", path)
style_file(path)
#> Warning: When processing file6b1f0f56be.R: <text>:1:3: unexpected numeric constant
#> 1: a 3
#> ^
#> Error in if (any(changed)) {: missing value where TRUE/FALSE needed
style_dir(dirname(path))
#> Warning: When processing ./file6b1f0f56be.R: <text>:1:3: unexpected numeric constant
#> 1: a 3
#> ^
#> Error in if (any(changed)) {: missing value where TRUE/FALSE needed
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 forgot how transform_lines_enc()
works, the error handling seems sufficient already. Do you need any(changed, na.rm = TRUE)
?
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.
Yes, with any(changed, na.rm = TRUE)
, we only get the first warning message. So I will undo my error handling implementation and adapt the tests.
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.
Also, do you need to submit utf8
to CRAN in order to submit styler
to CRAN, right?
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.
Yes, I'm about to submit utf8.
86fd011
to
b160f5a
Compare
and leave it to utf8::transform_lines_enc()
b160f5a
to
62fd6b7
Compare
Ok, I now reverted everything but kept the tests, so error handling is now done by |
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.
Awesome, thanks!
- Vignette on customizing styler (#145). - No line break after `switch()` and friends (#152). - Remove flat relicts completely (#151). - Don't reindent function calls and break line correctly for multi-line calls (#149). - Set space between "=" and "," (#150). - Make R CMD Check perfect (#148). - Adding tests for exception handling with invalid parse data (#139). - Fix indention by checking for all potential triggers (#142). - Fix un-indention (#135). - Support wide characters (#130). - No spaces around :, :: and :::. - Redesigning the API (#123). - Solve eq_sub indention in general (#125). - Minor refactorings. - Re-indent token-dependent (#119). - Supporting more indention patterns. - Allow raw indention. - Definitively fixing eol issue with comments. - Infrastructure. - Flattening out the parse table. - New rule: no space after ! -> !!! for tidyeval. - Fix spacing around '{'. - Don't drop tokens! Fixes #101. - EOL spaces in empty comments (and in general) (#98). - mal-indention in conditional statement due to wrong specification of indent_without_paren) (#95). - Complicated indentions based on arithmetic and special operators (#96). - indention interaction on with assignment operator and other operators (#97).
This closes #137.
For
style_text()
As you can see from the source code, it will still style all parsable files if there are any.
That's how it looks now. Much better I think.