Skip to content

Commit

Permalink
Bug system2 call error handling (#17)
Browse files Browse the repository at this point in the history
* added tryCatch error handling to system2 call

* capture error output of get-config

* version bump

* pre-commit autofixes

* bugfix, stderr vs stdout
now written in temp file

* pre-commit autofixes

---------

Co-authored-by: Tom Schwarzl <[email protected]>
Co-authored-by: tschwarzl <[email protected]>
  • Loading branch information
3 people authored Oct 21, 2024
1 parent 8cde65e commit 8f5e0b3
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions R/read_params.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,28 @@
read_params <- function(stage_path, return_list = FALSE) {
stage_path <- set_stage(stage_path)
tmp_config_file <- tempfile()
tmp_err_file <- tempfile()

tryCatch({
output <- system2(DSO_EXEC,
c("get-config",
shQuote(stage_path)),
stdout = tmp_config_file,
stderr = TRUE)
if (any(grepl("ERROR", output))) {
stop(paste("An error occurred when executing dso get-config: ", output))
stderr = tmp_err_file)

stderror <- readLines(tmp_err_file)

# error handling, display only rows after first error
# for better readability
if (output != 0 || any(grepl("ERROR", stderror))) {
stop(
paste("An error occurred when executing dso get-config:\n",
paste(
stderror[which(grepl("ERROR", stderror)) : length(stderror)],
collapse = "\n"
)
)
)
}
}, error = function(e) {
stop("An error occurred when executing dso get-config: ", e$message)
Expand Down

0 comments on commit 8f5e0b3

Please sign in to comment.