Skip to content

Commit 5fcd8de

Browse files
committed
Improve error paths
1 parent 6e5ce4f commit 5fcd8de

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
@@ -108,8 +108,10 @@ launch_remote <- function(
108108
if (is.null(tls)) tls <- envir[["tls"]]
109109

110110
if (length(remote) == 2L) {
111-
submit_job <- .subset2(rstudio(), ".rs.api.launcher.submitJob")
112-
new_container <- .subset2(rstudio(), ".rs.api.launcher.newContainer")
111+
tools <- posit_tools()
112+
is.environment(tools) || stop(._[["posit_api"]])
113+
submit_job <- .subset2(tools, ".rs.api.launcher.submitJob")
114+
new_container <- .subset2(tools, ".rs.api.launcher.newContainer")
113115
cluster <- remote[["name"]]
114116
container <- new_container(remote[["image"]])
115117
lapply(
@@ -475,12 +477,15 @@ cluster_config <- function(
475477
cloud_config <- function(platform = "posit") {
476478
switch(
477479
tolower(platform),
478-
posit = TRUE,
480+
posit = {
481+
tools <- posit_tools()
482+
is.environment(tools) || stop(._[["posit_api"]])
483+
get_info <- .subset2(tools, ".rs.api.launcher.getInfo")
484+
cluster <- get_info()[["clusters"]][[1L]]
485+
list(name = cluster[["name"]], image = cluster[["defaultImage"]])
486+
},
479487
stop(._[["platform_unsupported"]])
480488
)
481-
get_info <- .subset2(rstudio(), ".rs.api.launcher.getInfo")
482-
cluster <- get_info()[["clusters"]][[1L]]
483-
list(name = cluster[["name"]], image = cluster[["defaultImage"]])
484489
}
485490

486491
#' URL Constructors
@@ -567,11 +572,11 @@ find_dot <- function(args) {
567572
sel
568573
}
569574

570-
rstudio <- function() {
571-
idx <- match("tools:rstudio", search())
572-
is.na(idx) && stop(._[["rstudio_api"]])
575+
posit_tools <- function() {
576+
idx <- match("tools:rstudio", search(), nomatch = 0L)
577+
idx || return()
573578
tools <- as.environment(idx)
574579
feature_available <- .subset2(tools, ".rs.api.launcher.jobsFeatureAvailable")
575-
is.function(feature_available) && feature_available() || stop(._[["rstudio_api"]])
580+
is.function(feature_available) && feature_available() || return()
576581
tools
577582
}

R/mirai-package.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@
8484
not_found = "compute profile `%s` not found",
8585
numeric_n = "`n` must be numeric, did you mean to provide `url`?",
8686
platform_unsupported = "`platform` is currently not supported",
87-
rstudio_api = "cannot be used outside of a Posit Workbench environment",
87+
posit_api = "this launch configuration can only be used from Posit Workbench",
8888
sync_daemons = "mirai: initial sync with daemon(s) [%d secs elapsed]",
8989
sync_dispatcher = "mirai: initial sync with dispatcher [%d secs elapsed]",
9090
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
@@ -42,7 +42,8 @@ test_true(grepl("5555", local_url(tcp = TRUE, port = 5555), fixed = TRUE))
4242
test_type("list", ssh_config("ssh://remotehost"))
4343
test_type("list", ssh_config("ssh://remotehost", tunnel = TRUE))
4444
test_type("list", cluster_config())
45-
test_class("error", tryCatch(cloud_config(), error = identity))
45+
test_error(cloud_config(platform = ""), "not supported")
46+
test_error(cloud_config(platform = "posit"), "can only be used from Posit Workbench")
4647
test_true(is_mirai_interrupt(r <- mirai:::mk_interrupt_error()))
4748
test_print(r)
4849
test_true(is_mirai_error(r <- `class<-`("Error in: testing\n", c("miraiError", "errorValue", "try-error"))))

0 commit comments

Comments
 (0)