Skip to content

Commit 602e44d

Browse files
committed
chain error a bit differently so that system_command_status_error are wrapped before wrapping all errors
1 parent 850a66e commit 602e44d

File tree

2 files changed

+35
-30
lines changed

2 files changed

+35
-30
lines changed

R/quarto.R

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,16 @@ quarto_run <- function(
148148
env = custom_env,
149149
...
150150
),
151-
error = function(e) wrap_quarto_error(e, args, .call = .call)
151+
system_command_status_error = function(e) {
152+
wrap_quarto_error(e, args, .call = .call)
153+
},
154+
error = function(e) {
155+
cli::cli_abort(
156+
c("!" = "Error running quarto CLI from R."),
157+
call = .call,
158+
parent = e
159+
)
160+
}
152161
)
153162

154163
invisible(res)
@@ -308,38 +317,30 @@ quarto_binary_sitrep <- function(verbose = TRUE, debug = FALSE) {
308317

309318

310319
wrap_quarto_error <- function(cnd, args, .call = rlang::caller_env()) {
311-
if (!inherits(cnd, "system_command_status_error")) {
312-
cli::cli_abort(
313-
c("!" = "Error running quarto CLI from R."),
314-
call = .call,
315-
parent = cnd
320+
msg <- c(x = "Error returned by quarto CLI.")
321+
# if there is an error message from quarto CLI, add it to the message
322+
if (cnd$stderr != "") {
323+
quarto_error_msg <- xfun::split_lines(cnd$stderr)
324+
names(quarto_error_msg) <- rep(" ", length(quarto_error_msg))
325+
msg <- c(
326+
msg,
327+
" " = paste0(rep("-", nchar(msg)), collapse = ""),
328+
quarto_error_msg
316329
)
317-
} else {
318-
msg <- c(x = "Error returned by quarto CLI.")
319-
# if there is an error message from quarto CLI, add it to the message
320-
if (cnd$stderr != "") {
321-
quarto_error_msg <- xfun::split_lines(cnd$stderr)
322-
names(quarto_error_msg) <- rep(" ", length(quarto_error_msg))
323-
msg <- c(
324-
msg,
325-
" " = paste0(rep("-", nchar(msg)), collapse = ""),
326-
quarto_error_msg
327-
)
328-
}
329-
330-
# if `--quiet` has been set, quarto CLI won't report any error (cnd$stderr will be empty)
331-
# So remind user to run without `--quiet` to see the full error message
332-
if (cli_arg_quiet() %in% args) {
333-
msg <- c(
334-
msg,
335-
"i" = "Rerun with `quiet = FALSE` to see the full error message."
336-
)
337-
}
330+
}
338331

339-
cli::cli_abort(
332+
# if `--quiet` has been set, quarto CLI won't report any error (cnd$stderr will be empty)
333+
# So remind user to run without `--quiet` to see the full error message
334+
if (cli_arg_quiet() %in% args) {
335+
msg <- c(
340336
msg,
341-
call = .call,
342-
parent = cnd,
337+
"i" = "Rerun with `quiet = FALSE` to see the full error message."
343338
)
344339
}
340+
341+
cli::cli_abort(
342+
msg,
343+
call = .call,
344+
parent = cnd,
345+
)
345346
}

tests/testthat/_snaps/quarto.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
quarto_run(c("rend", "--quiet"))
55
Condition
66
Error:
7+
! Error running quarto CLI from R.
8+
Caused by error:
79
x Error returned by quarto CLI.
810
i Rerun with `quiet = FALSE` to see the full error message.
911
Caused by error:
@@ -15,6 +17,8 @@
1517
quarto_inspect()
1618
Condition
1719
Error in `quarto_inspect()`:
20+
! Error running quarto CLI from R.
21+
Caused by error in `quarto_inspect()`:
1822
x Error returned by quarto CLI.
1923
-----------------------------
2024
ERROR: Book chapter 'intro.qmd' not found

0 commit comments

Comments
 (0)