Skip to content

Commit 3b328f9

Browse files
committed
Improve error paths
1 parent e889b79 commit 3b328f9

File tree

3 files changed

+18
-12
lines changed

3 files changed

+18
-12
lines changed

R/launchers.R

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,10 @@ launch_remote <- function(n = 1L, remote = remote_config(), ..., tls = NULL, .co
9595
if (is.null(tls)) tls <- envir[["tls"]]
9696

9797
if (length(remote) == 2L) {
98-
submit_job <- .subset2(rstudio(), ".rs.api.launcher.submitJob")
99-
new_container <- .subset2(rstudio(), ".rs.api.launcher.newContainer")
98+
tools <- posit_tools()
99+
is.environment(tools) || stop(._[["posit_api"]])
100+
submit_job <- .subset2(tools, ".rs.api.launcher.submitJob")
101+
new_container <- .subset2(tools, ".rs.api.launcher.newContainer")
100102
cluster <- remote[["name"]]
101103
container <- new_container(remote[["image"]])
102104
lapply(
@@ -437,12 +439,15 @@ cluster_config <- function(command = "sbatch", options = "", rscript = "Rscript"
437439
cloud_config <- function(platform = "posit") {
438440
switch(
439441
tolower(platform),
440-
posit = TRUE,
442+
posit = {
443+
tools <- posit_tools()
444+
is.environment(tools) || stop(._[["posit_api"]])
445+
get_info <- .subset2(tools, ".rs.api.launcher.getInfo")
446+
cluster <- get_info()[["clusters"]][[1L]]
447+
list(name = cluster[["name"]], image = cluster[["defaultImage"]])
448+
},
441449
stop(._[["platform_unsupported"]])
442450
)
443-
get_info <- .subset2(rstudio(), ".rs.api.launcher.getInfo")
444-
cluster <- get_info()[["clusters"]][[1L]]
445-
list(name = cluster[["name"]], image = cluster[["defaultImage"]])
446451
}
447452

448453
#' URL Constructors
@@ -530,11 +535,11 @@ find_dot <- function(args) {
530535
sel
531536
}
532537

533-
rstudio <- function() {
534-
idx <- match("tools:rstudio", search())
535-
is.na(idx) && stop(._[["rstudio_api"]])
538+
posit_tools <- function() {
539+
idx <- match("tools:rstudio", search(), nomatch = 0L)
540+
idx || return()
536541
tools <- as.environment(idx)
537542
feature_available <- .subset2(tools, ".rs.api.launcher.jobsFeatureAvailable")
538-
is.function(feature_available) && feature_available() || stop(._[["rstudio_api"]])
543+
is.function(feature_available) && feature_available() || return()
539544
tools
540545
}

R/mirai-package.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@
8181
not_found = "compute profile `%s` not found",
8282
numeric_n = "`n` must be numeric, did you mean to provide `url`?",
8383
platform_unsupported = "`platform` is currently not supported",
84-
rstudio_api = "cannot be used outside of a Posit Workbench environment",
84+
posit_api = "this launch configuration can only be used from Posit Workbench",
8585
sync_daemons = "mirai: initial sync with daemon(s) [%d secs elapsed]",
8686
sync_dispatcher = "mirai: initial sync with dispatcher [%d secs elapsed]",
8787
within_map = "cannot create local daemons from within mirai map"

tests/tests.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ test_true(grepl("5555", local_url(tcp = TRUE, port = 5555), fixed = TRUE))
4343
test_type("list", ssh_config("ssh://remotehost"))
4444
test_type("list", ssh_config("ssh://remotehost", tunnel = TRUE))
4545
test_type("list", cluster_config())
46-
test_class("error", tryCatch(cloud_config(), error = identity))
46+
test_error(cloud_config(platform = ""), "not supported")
47+
test_error(cloud_config(platform = "posit"), "can only be used from Posit Workbench")
4748
test_true(is_mirai_interrupt(r <- mirai:::mk_interrupt_error()))
4849
test_print(r)
4950
test_true(is_mirai_error(r <- `class<-`("Error in: testing\n", c("miraiError", "errorValue", "try-error"))))

0 commit comments

Comments
 (0)