diff --git a/DESCRIPTION b/DESCRIPTION index c8c4862..44b9bf2 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -30,6 +30,7 @@ Depends: Imports: tibble Suggests: + cli, covr, devtools, diffdf, @@ -42,6 +43,7 @@ Suggests: methods, miniUI, pkgdown, + readxl, rmarkdown, roxygen2, spelling, diff --git a/NEWS.md b/NEWS.md index 30cecff..b6921b8 100644 --- a/NEWS.md +++ b/NEWS.md @@ -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) - - -## Various - -
- -Developer Notes +- Added alternative text to the pharmaverse badge and logo. (#114) - Added copyright holder logos. (#113) diff --git a/data-raw/create_adams_data.R b/data-raw/create_adams_data.R index 14ea77d..fd59934 100644 --- a/data-raw/create_adams_data.R +++ b/data-raw/create_adams_data.R @@ -2,6 +2,7 @@ library(readxl) library(jsonlite) +library(cli) json_file <- "inst/extdata/adams-specs.json" excel_file <- "inst/extdata/adams-specs.xlsx" @@ -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 @@ -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"))