From b4ff36dfa8bef293a3e4f06619682e9ad8a84bb1 Mon Sep 17 00:00:00 2001 From: pat-s Date: Mon, 29 Jul 2024 14:34:01 +0200 Subject: [PATCH] tryCatch error in pkgbuild::build --- .woodpecker/build.yaml | 15 +++++++++++---- R/build_binaries.R | 27 +++++++++++++++++++-------- 2 files changed, 30 insertions(+), 12 deletions(-) diff --git a/.woodpecker/build.yaml b/.woodpecker/build.yaml index a10cdc6..f14fba4 100644 --- a/.woodpecker/build.yaml +++ b/.woodpecker/build.yaml @@ -49,13 +49,20 @@ steps: - R -q -e 'options(crayon.enabled = TRUE, Ncpus = 6, future.globals.onReference = "error", repos = structure(c(getOption("repos"),INLA="https://inla.r-inla-download.org/R/stable"))); pkgs = tools::CRAN_package_db()[[1]][${BLOCK}]; library(rBinaries); future::plan("multisession", workers = 6, rscript_startup = quote(options(crayon.enabled = TRUE))); foo = lapply(pkgs, function(x) build_binary_package(x, build_for_minor=FALSE, debug = TRUE, force = TRUE))' backend_options: kubernetes: + # resources: + # requests: + # memory: 25Gi + # cpu: 12000m + # limits: + # memory: 28Gi + # cpu: 16000m resources: requests: - memory: 25Gi - cpu: 12000m + memory: 4Gi + cpu: 2000m limits: - memory: 28Gi - cpu: 16000m + memory: 4Gi + cpu: 2000m nodeSelector: kubernetes.io/arch: 'arm64' - name: Upload PACKAGES files diff --git a/R/build_binaries.R b/R/build_binaries.R index 80279e9..1ccd469 100644 --- a/R/build_binaries.R +++ b/R/build_binaries.R @@ -69,7 +69,7 @@ build_binary_package <- function(package_name, tag = NULL, codename = NULL, }, # NB: here we need to use conditionMessage() to extract the actual error - as opposed to using $stderr for errors within the tryCatch used in the future* calls error = function(e) { - message(sprintf("Error in installing dependencies for package %s with tag %s: %s", package_name[1], tag[1], e)) + cli::cli_alert_warning("Error in installing dependencies for package {.pkg {package_name{1]}} with tag {.field {tag[1]}}: {e}") store_build_metadata(package_name[1], tag[1], platform, error_occurred = TRUE, force = TRUE, error = conditionMessage(e)) return(TRUE) } @@ -101,7 +101,7 @@ build_binary_package <- function(package_name, tag = NULL, codename = NULL, dbDisconnect(con) }, error = function(e) { - message(sprintf("Error in processing package %s with tag %s: %s", x, y, e)) + cli::cli_alert_warning("Error in starting build command for package {.pkg {package_name}} with tag {.field {tag}}: {e}") local_clone_dir_single <- sprintf("%s/%s_%s", local_clone_dir, x, y) unlink(local_clone_dir_single, force = TRUE, recursive = TRUE) # only stderr contains the important information why the build failed @@ -159,15 +159,26 @@ build_single_tag <- function( cli::cli_alert("{.fun build_single_tag}: (2/3) Building package {.pkg {package_name}} with tag {.field {tag}}.") t1 <- Sys.time() - dump <- pkgbuild::build( - path = sprintf("%s", local_clone_dir_single), - binary = TRUE, vignettes = FALSE, - dest_path = dir_out_bin, quiet = TRUE + tryCatch( + { + dump <- pkgbuild::build( + path = sprintf("%s", local_clone_dir_single), + binary = TRUE, vignettes = FALSE, + dest_path = dir_out_bin, quiet = TRUE + ) + }, + error = function(e) { + cli::cli_alert_warning("Error in starting build command for package {.pkg {package_name}} with tag {.field {tag}}: {e}") + local_clone_dir_single <- sprintf("%s/%s_%s", local_clone_dir, package_name, tag) + unlink(local_clone_dir_single, force = TRUE, recursive = TRUE) + store_build_metadata(package_name, tag, platform, error_occurred = TRUE, force = TRUE, error = "Error trying to initiate pkgbuild - likely a non-valid R package structure") + return(invisible(TRUE)) + } ) if (!file.exists(sprintf("%s/%s_%s.tar.gz", dir_out_bin, package_name, tag))) { if (debug) { - cli::cli_alert_info('{.fun build_single_tag}: Moving package from {.path {sprintf("%s/%s_%s_R_aarch64-unknown-linux-gnu.tar.gz", dir_out_bin, package_name, tag))}} to {.path {sprintf("%s/%s_%s.tar.gz", dir_out_bin, package_name, tag)}}') + cli::cli_alert_info('{.fun build_single_tag}: Moving package from {.path {sprintf("%s/%s_%s_R_aarch64-unknown-linux-gnu.tar.gz", dir_out_bin, package_name, tag)}} to {.path {sprintf("%s/%s_%s.tar.gz", dir_out_bin, package_name, tag)}}') } # double-check that file exists (some packages like https://github.com/cran/BACCO/tree/1.0-14 don't include R/ and hence don't procude a valid binary) if (fs::file_exists(sprintf("%s/%s_%s_R_aarch64-unknown-linux-gnu.tar.gz", dir_out_bin, package_name, tag))) { @@ -177,7 +188,7 @@ build_single_tag <- function( sprintf("%s/%s_%s.tar.gz", dir_out_bin, package_name, tag) ) } else { - cli::cli_alert_info('{.fun build_single_tag}: File for package {.pkg {package_name}} {.field {tag}} at {.path {sprintf("%s/%s_%s_R_aarch64-unknown-linux-gnu.tar.gz", dir_out_bin, package_name, tag))}} does not exist - skipping.') + cli::cli_alert_info('{.fun build_single_tag}: File for package {.pkg {package_name}} {.field {tag}} at {.path {sprintf("%s/%s_%s_R_aarch64-unknown-linux-gnu.tar.gz", dir_out_bin, package_name, tag)}} does not exist - skipping.') } } else { cli::cli_alert_warning('{.fun build_single_tag}: Binary {sprintf("%s_%s.tar.gz", package_name, tag)} already exists. Skipping copy.')