diff --git a/DESCRIPTION b/DESCRIPTION index b98d371..298d260 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: condathis Title: Run Any CLI Tool on a 'Conda' Environment -Version: 0.1.1 +Version: 0.1.1.9001 Authors@R: c( person("Lucio", "Queiroz", , "luciorqueiroz@gmail.com", role = c("aut", "cre", "cph"), comment = c(ORCID = "0000-0002-6090-1834")), diff --git a/NEWS.md b/NEWS.md index 0c12260..fff8008 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,10 @@ +# condathis 0.1.2 (dev) + +## Minor improvements and fixes + +* Fix parsing of error messages with curly braces in `run()` and `run_bin()`, + in the rethrown error, when `error = "cancel"`. + # condathis 0.1.1 ## Minor improvements and fixes diff --git a/R/rethrow_error_cmd.R b/R/rethrow_error_cmd.R index a1c0dfe..686b5ee 100644 --- a/R/rethrow_error_cmd.R +++ b/R/rethrow_error_cmd.R @@ -12,8 +12,17 @@ rethrow_error_cmd <- function(expr, env = parent.frame()) { if (isFALSE(is.null(err_cnd))) { additional_lines <- NULL if (isTRUE("stderr" %in% names(err_cnd))) { + err_vector <- stringr::str_replace_all( + stringr::str_replace_all( + string = err_cnd[["stderr"]], + pattern = stringr::fixed("{"), + replacement = stringr::fixed("{{") + ), + pattern = stringr::fixed("}"), + replacement = stringr::fixed("}}") + ) additional_lines <- stringr::str_split( - string = stringr::str_trim(err_cnd[["stderr"]]), + string = stringr::str_trim(err_vector), pattern = stringr::regex("\\R"), simplify = FALSE )[[1]] diff --git a/R/rethrow_error_run.R b/R/rethrow_error_run.R index 95fada8..e85399f 100644 --- a/R/rethrow_error_run.R +++ b/R/rethrow_error_run.R @@ -12,8 +12,17 @@ rethrow_error_run <- function(expr, env = parent.frame()) { if (isFALSE(is.null(err_cnd)) && !isFALSE(env[["error_var"]])) { additional_lines <- NULL if (isTRUE("stderr" %in% names(err_cnd))) { + err_vector <- stringr::str_replace_all( + stringr::str_replace_all( + string = err_cnd[["stderr"]], + pattern = stringr::fixed("{"), + replacement = stringr::fixed("{{") + ), + pattern = stringr::fixed("}"), + replacement = stringr::fixed("}}") + ) additional_lines <- stringr::str_split( - string = stringr::str_trim(err_cnd[["stderr"]]), + string = stringr::str_trim(err_vector), pattern = stringr::regex("\\R"), simplify = FALSE )[[1]] diff --git a/README.md b/README.md index 9ca98b7..21a3989 100644 --- a/README.md +++ b/README.md @@ -211,16 +211,16 @@ For example, the system’s `curl` is of a specific version: ``` r libcurlVersion() -#> [1] "8.7.1" +#> [1] "8.11.1" #> attr(,"ssl_version") -#> [1] "(SecureTransport) LibreSSL/3.3.6" +#> [1] "OpenSSL/3.4.0 (SecureTransport)" #> attr(,"libssh_version") -#> [1] "" +#> [1] "libssh2/1.11.1" #> attr(,"protocols") #> [1] "dict" "file" "ftp" "ftps" "gopher" "gophers" "http" -#> [8] "https" "imap" "imaps" "ldap" "ldaps" "mqtt" "pop3" -#> [15] "pop3s" "rtsp" "smb" "smbs" "smtp" "smtps" "telnet" -#> [22] "tftp" +#> [8] "https" "imap" "imaps" "mqtt" "pop3" "pop3s" "rtsp" +#> [15] "scp" "sftp" "smb" "smbs" "smtp" "smtps" "telnet" +#> [22] "tftp" "ws" "wss" ``` However, we can choose to use a different version of `curl` run in a diff --git a/tests/testthat/test-rethrow_error.R b/tests/testthat/test-rethrow_error.R new file mode 100644 index 0000000..c250909 --- /dev/null +++ b/tests/testthat/test-rethrow_error.R @@ -0,0 +1,46 @@ +testthat::test_that("Do not execute code in curl braces", { + testthat::skip_if_offline() + testthat::skip_on_cran() + + px_res <- create_env( + packages = c("r-base=4.1.3", "r-devtools"), + env_name = "condathis-test-env" + ) + + testthat::expect_error( + object = { + run( + "R", "-q", "-s", "-e", "stop(\"{ 5 + x }\")", + env_name = "condathis-test-env", + verbose = "silent", + error = "cancel" + ) + }, + class = "condathis_run_status_error" + ) + + testthat::expect_error( + object = { + run( + "R", "-q", "-s", "-e", "stop(\"{{{ 5 + x }}}\")", + env_name = "condathis-test-env", + verbose = "silent", + error = "cancel" + ) + }, + class = "condathis_run_status_error" + ) + + px_res <- rethrow_error_run( + expr = { + run( + "R", "-q", "-s", "-e", "stop(\"{{{ 5 + x }}}\")", + env_name = "condathis-test-env", + verbose = "silent", + error = "continue" + ) + } + ) + + testthat::expect_true(px_res$status != 0L) +})