summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRicardo Wurmus <rekado@elephly.net>2022-04-07 09:26:01 +0200
committerRicardo Wurmus <rekado@elephly.net>2022-04-07 09:26:01 +0200
commitc7ef26e798556c6906034db65d369f11c74c2a3a (patch)
tree4d70adbccebc3376cb0b1063118ef8b672bbee45
parent2c0c2d7e77773f7b252dde2818a4d59e52d0f85b (diff)
Fail early if Guix command does not exist.
-rw-r--r--R/guix.install.R8
-rw-r--r--inst/unitTests/test_guix.install.R3
2 files changed, 11 insertions, 0 deletions
diff --git a/R/guix.install.R b/R/guix.install.R
index 66bb340..49d607a 100644
--- a/R/guix.install.R
+++ b/R/guix.install.R
@@ -18,6 +18,14 @@
guix.install <- function (package, profile = NULL, guix = "guix", archive = NULL)
{
+ ## Abort if we can't execute Guix.
+ error <- suppressWarnings (system2 (guix, c("describe"), stderr=NULL, stdout=NULL))
+ if (error == 127) {
+ stop (paste("Failed to run Guix command ", guix, ". Is it on PATH?"))
+ } else if (error != 0) {
+ stop (paste("Failed to run Guix command ", guix, ". Error code: ", error))
+ }
+
if (is.null (profile)) {
## Use the default profile unless otherwise specified.
guix_profile <- Sys.getenv ("GUIX_PROFILE", unset = NA)
diff --git a/inst/unitTests/test_guix.install.R b/inst/unitTests/test_guix.install.R
index f762744..3593f11 100644
--- a/inst/unitTests/test_guix.install.R
+++ b/inst/unitTests/test_guix.install.R
@@ -1,3 +1,6 @@
test.guix.install <- function () {
checkException(guix.install("foo", guix="/doesnot/exist"))
+
+ msg <- geterrmessage()
+ checkTrue(grepl("Failed to run Guix command", msg))
}