Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ Depends:
Imports:
tibble
Suggests:
cli,
covr,
devtools,
diffdf,
Expand All @@ -42,6 +43,7 @@ Suggests:
methods,
miniUI,
pkgdown,
readxl,
rmarkdown,
roxygen2,
spelling,
Expand Down
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
38 changes: 32 additions & 6 deletions data-raw/create_adams_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

library(readxl)
library(jsonlite)
library(cli)

json_file <- "inst/extdata/adams-specs.json"
excel_file <- "inst/extdata/adams-specs.xlsx"
Expand Down Expand Up @@ -147,6 +148,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,18 +217,24 @@ 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)
}


# Display error message when a template fails
cli_div(theme = list(".error-detail" = list(color = "red")))
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))
if (!is.null(res$exit_code) && res$exit_code != 0) {
cli_alert_danger("template {.val {res$template}} failed - package {.pkg {res$pkg}}")
cli_alert_danger("Error details:")
error_lines <- strsplit(res$output, "\n")[[1]]
for (line in error_lines) {
cli_text("{.error-detail {line}}")
}
cli_text("")
}
}
cli_end()

# Generate the documentation ----
roxygen2::roxygenize(".", roclets = c("rd", "collate", "namespace"))
Loading