Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 2 additions & 8 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,9 @@

- Imported `{tibble}` so that tibble formatting is not lost. (#95)

- Added alternative text to the pharmaverse badge and logo (#114)
- Added clearer error messages for template failures. (#121)

</details>

## Various

<details>

<summary>Developer Notes</summary>
- Added alternative text to the pharmaverse badge and logo. (#114)

- Added copyright holder logos. (#113)

Expand Down
51 changes: 44 additions & 7 deletions data-raw/create_adams_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,25 @@ run_template <- function(tp) {
}
}

# Wrapper Function for Error Handling
safe_run_template <- function(tp) {
tryCatch(
run_template(tp),
error = function(e) {
list(
pkg = pkg,
template = tp,
exit_code = 1,
output = paste(
"ERROR in template:", tp, "\n",
"Package:", pkg, "\n",
"Message:", e$message, "\n",
"Call:", paste(capture.output(traceback()), collapse = "\n")
)
)
}
)
}

if (update_pkg) {
github_pat <- Sys.getenv("GITHUB_TOKEN") # in case of run through github workflows
Expand Down Expand Up @@ -197,16 +216,34 @@ for (pkg in packages_list) {
# for (tp in templates) {
# run_template(tp)
# }
results <- parallel::mclapply(templates, run_template, mc.cores = length(templates))
results <- parallel::mclapply(templates, safe_run_template, mc.cores = length(templates))
all_results <- c(all_results, results)
}


for (res in all_results) {
if (!is.null(res$exit_code)) {
print(sprintf("template %s failed - package %s", res$template, res$pkg))
print("error:")
cat(sprintf("%s\n\n", res$output))
# Display error message when a template fails
if (requireNamespace("cli", quietly = TRUE)) {
Comment thread
bundfussr marked this conversation as resolved.
Outdated
# Using cli for colored and formatted output
cli::cli_div(theme = list(".error-detail" = list(color = "red")))
for (res in all_results) {
if (!is.null(res$exit_code) && res$exit_code != 0) {
cli::cli_alert_danger("template {.val {res$template}} failed - package {.pkg {res$pkg}}")
cli::cli_alert_danger("Error details:")
error_lines <- strsplit(res$output, "\n")[[1]]
for (line in error_lines) {
cli::cli_text("{.error-detail {line}}")
}
cli::cli_text("")
}
}
cli::cli_end()
} else {
Comment thread
bundfussr marked this conversation as resolved.
Outdated
# Fallback - plain text output (if cli is not installed)
for (res in all_results) {
if (!is.null(res$exit_code) && res$exit_code != 0) {
cat(sprintf("template %s failed - package %s\n", res$template, res$pkg))
cat("error:\n")
cat(sprintf("%s\n\n", res$output))
}
}
}

Expand Down
Loading