Repository navigation
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
| #' 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.
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.
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 neededThere was a problem hiding this comment.
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.
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.
Also, do you need to submit utf8 to CRAN in order to submit styler to CRAN, right?
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 |
- 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.