Skip to content

Commit b1ddf7a

Browse files
Merge pull request #423 from lorenzwalthert/issue-422
more context for `parsable-R`
2 parents 0d2d04f + e2e384d commit b1ddf7a

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

NEWS.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ editor_options:
44
wrap: 72
55
---
66

7+
# precommit v0.3.1.9000
8+
9+
- `parsable-R` hook now gives more context on where and how parsing
10+
fails (#423).
11+
712
# precommit v0.3.1
813

914
**User visible changes**

inst/hooks/exported/parsable-R.R

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ out <- lapply(files, function(path) {
1111

1212
tryCatch(
1313
parse(path_),
14-
error = function(x) stop("File ", path, " is not parsable", call. = FALSE)
14+
error = function(error) {
15+
cat(c("File ", path, " is not parsable. Full context:\n"))
16+
stop(conditionMessage(error), call. = FALSE)
17+
}
1518
)
1619
})

tests/testthat/test-hooks.R

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,12 +169,13 @@ run_test("parsable-R",
169169
)
170170

171171
# failure
172-
run_test("parsable-R", suffix = "-fail.R", std_err = "not parsable")
172+
run_test("parsable-R", suffix = "-fail.R", std_out = "Full context", std_err = "1 1")
173173

174174
run_test(
175175
"parsable-R",
176176
suffix = "-fail.Rmd",
177-
std_err = "parsable-R-fail.Rmd is not parsable"
177+
std_out = "parsable-R-fail.Rmd",
178+
std_err = "1 1"
178179
)
179180

180181
### . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ..

0 commit comments

Comments
 (0)