Skip to content

Commit

Permalink
added error handling around processx::run("squeue"). Will throw warni…
Browse files Browse the repository at this point in the history
…ng and likely errors because option never gets set.
  • Loading branch information
mduncans committed Sep 6, 2024
1 parent d71ed22 commit 930a989
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions R/zzz.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,23 @@
}

.onLoad <- function(libname, pkgname) {
processx_output <- processx::run("squeue", args = "--version")
if (processx_output$status != 0) {
warning("squeue not installed correctly")
} else {
# stdout format is "slurm major.minor.patch/n"
version <- strsplit(processx_output$stdout," ")[[1]][[2]] %>%
trimws() %>%
package_version()
options("squeue.version" = version)
result <- tryCatch(
{processx::run("squeue", args = "--version")},
error = function(e) {
message("Warning: 'squeue' command not found or failed to run.")
return(NULL)
}
)

if (!is.null(result)) {
if (result$status != 0) {
warning("squeue not installed correctly")
} else {
# stdout format is "slurm major.minor.patch/n"
version <- strsplit(result$stdout," ")[[1]][[2]] %>%
trimws() %>%
package_version()
options("squeue.version" = version)
}
}
}

0 comments on commit 930a989

Please sign in to comment.