Skip to content

Commit ca0a3cb

Browse files
committed
Improve error paths
1 parent 925cde6 commit ca0a3cb

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

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

487492
#' URL Constructors
@@ -568,11 +573,11 @@ find_dot <- function(args) {
568573
sel
569574
}
570575

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

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)