Skip to content

Commit

Permalink
Correctly capture stderr in pandoc_run (#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
cderv authored Sep 22, 2023
1 parent ee86163 commit ecad641
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 4 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: pandoc
Title: Manage and Run Universal Converter 'Pandoc' from 'R'
Version: 0.2.0.9000
Version: 0.2.0.9001
Authors@R: c(
person("Christophe", "Dervieux", , "[email protected]", role = c("aut", "cre"),
comment = c(ORCID = "0000-0003-4474-2498")),
Expand Down
6 changes: 4 additions & 2 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
# pandoc (development version)

- Correctly order error message of Pandoc failure (thanks, \@hadley, #39).

# pandoc 0.2.0

- input and output path containing short path version using `~` now works (thanks, @olivroy, #31)
- input and output path containing short path version using `~` now works (thanks, \@olivroy, #31)

- `pandoc_install()` now works for Pandoc 3.1.2 and above on Mac as Pandoc bundles' name have changed.

- `pandoc_install()` works now on Mac M1.

- `pandoc_convert()` and `pandoc_export_*()` now handles filepath with space (thanks, @krlmlr, #32).
- `pandoc_convert()` and `pandoc_export_*()` now handles filepath with space (thanks, \@krlmlr, #32).

# pandoc 0.1.0

Expand Down
2 changes: 1 addition & 1 deletion R/pandoc-run.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pandoc_run <- function(args, version = "default") {
# Seems like expansion is needed (https://github.com/cderv/pandoc/pull/15)
# not doing it on windows because `~` does not mean the same for {fs}
if (pandoc_os() != "windows") bin <- fs::path_expand(bin)
res <- suppressWarnings(system2(bin, args, stdout = TRUE))
res <- suppressWarnings(system2(bin, args, stdout = TRUE, stderr = TRUE))
status <- attr(res, "status", TRUE)
if (length(status) > 0 && status > 0) {
rlang::abort(c("Running Pandoc failed with following error", res))
Expand Down
9 changes: 9 additions & 0 deletions tests/testthat/_snaps/pandoc-run.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Pandoc error is shown

Code
pandoc::pandoc_run(c("--to", "word", tmp))
Condition
Error in `pandoc::pandoc_run()`:
! Running Pandoc failed with following error
* Unknown output format word

11 changes: 11 additions & 0 deletions tests/testthat/test-pandoc-run.R
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,14 @@ test_that("rmarkdown version is correctly set / reset", {
expect_equal(rmarkdown::find_pandoc(), before_with)
expect_equal(pandoc_version(), as.numeric_version("2.18"))
})

test_that("Pandoc error is shown", {
skip_on_cran()
skip_if_offline()
suppressMessages(pandoc_install("2.18"))
local_pandoc_version("2.18")
tmp <- withr::local_tempfile(fileext = ".md")
write_utf8("dummy", tmp)
expect_identical(pandoc::pandoc_run(c("--to", "gfm", tmp)), "dummy")
expect_snapshot(pandoc::pandoc_run(c("--to", "word", tmp)), error = TRUE)
})

0 comments on commit ecad641

Please sign in to comment.