From 9efb23c16dc5899da41348009baa6f81b7a87b46 Mon Sep 17 00:00:00 2001 From: Lorenz Walthert Date: Thu, 23 Jun 2022 18:46:50 +0200 Subject: [PATCH 1/2] more context --- NEWS.md | 5 +++++ inst/hooks/exported/parsable-R.R | 5 ++++- tests/testthat/test-hooks.R | 2 +- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/NEWS.md b/NEWS.md index d6c9b1d4f..80ed4dc48 100644 --- a/NEWS.md +++ b/NEWS.md @@ -4,6 +4,11 @@ editor_options: wrap: 72 --- +# precommit v0.3.1.9000 + +- `parsable-R` hook now gives more context on where and how parsing + fails (#423). + # precommit v0.3.1 **User visible changes** diff --git a/inst/hooks/exported/parsable-R.R b/inst/hooks/exported/parsable-R.R index 392dffff9..e8501806c 100755 --- a/inst/hooks/exported/parsable-R.R +++ b/inst/hooks/exported/parsable-R.R @@ -11,6 +11,9 @@ out <- lapply(files, function(path) { tryCatch( parse(path_), - error = function(x) stop("File ", path, " is not parsable", call. = FALSE) + error = function(error) { + cat(c("File ", path, " is not parsable. Full context:\n")) + stop(conditionMessage(error), call. = FALSE) + } ) }) diff --git a/tests/testthat/test-hooks.R b/tests/testthat/test-hooks.R index aea3a511c..7f07b4219 100644 --- a/tests/testthat/test-hooks.R +++ b/tests/testthat/test-hooks.R @@ -169,7 +169,7 @@ run_test("parsable-R", ) # failure -run_test("parsable-R", suffix = "-fail.R", std_err = "not parsable") +run_test("parsable-R", suffix = "-fail.R", std_out = "Full context", std_err = "1 1") run_test( "parsable-R", From e2e384d3250d39681d1e2bcdba2930af6963c1ca Mon Sep 17 00:00:00 2001 From: Lorenz Walthert Date: Thu, 23 Jun 2022 18:59:51 +0200 Subject: [PATCH 2/2] fix erorr --- tests/testthat/test-hooks.R | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/testthat/test-hooks.R b/tests/testthat/test-hooks.R index 7f07b4219..fce703481 100644 --- a/tests/testthat/test-hooks.R +++ b/tests/testthat/test-hooks.R @@ -174,7 +174,8 @@ run_test("parsable-R", suffix = "-fail.R", std_out = "Full context", std_err = " run_test( "parsable-R", suffix = "-fail.Rmd", - std_err = "parsable-R-fail.Rmd is not parsable" + std_out = "parsable-R-fail.Rmd", + std_err = "1 1" ) ### . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ..