Skip to content

Commit 27537d5

Browse files
committed
extend messaging to account for >2 classes
1 parent 40eb96a commit 27537d5

3 files changed

Lines changed: 26 additions & 9 deletions

File tree

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export(checkNegValueDS)
2626
export(checkPermissivePrivacyControlLevel)
2727
export(classDS)
2828
export(colnamesDS)
29+
export(colnamesDS2)
2930
export(completeCasesDS)
3031
export(corDS)
3132
export(corTestDS)

R/utils.R

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#' @noRd
99
.loadServersideObject <- function(x) {
1010
tryCatch(
11-
get(x, envir = parent.frame(2)),
11+
get(x, envir = parent.frame(2)),
1212
error = function(e) {
1313
stop("The server-side object", " '", x, "' ", "does not exist")
1414
}
@@ -28,15 +28,15 @@
2828
#' @noRd
2929
.checkClass <- function(obj, obj_name, permitted_classes) {
3030
typ <- class(obj)
31-
31+
3232
if (!any(permitted_classes %in% typ)) {
3333
msg <- glue(
34-
"The server-side object must be of type {glue_collapse(permitted_classes, sep = ' or ')}. ",
35-
"'{obj_name}' is type {typ}."
34+
"The server-side object must be of type {glue_collapse(permitted_classes, sep = ', ', last = ' or ')}. ",
35+
"'{obj_name}' is type {glue_collapse(typ, sep = ', ', last = ' and ')}."
3636
)
37-
37+
3838
stop(msg, call. = FALSE)
3939
}
40-
40+
4141
invisible(TRUE)
4242
}

tests/testthat/test-smk-utils.R

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,27 @@ test_that(".checkClass() passes for correct class", {
4141
)
4242
})
4343

44-
test_that(".checkClass() throws informative error for wrong class", {
44+
test_that(".checkClass() throws informative error for wrong class with one target class", {
4545
x <- list(a = 1)
4646
expect_error(
47-
.checkClass(x, "x", c("data.frame", "matrix")),
48-
regexp = "must be of type data.frame or matrix"
47+
.checkClass(x, "x", "data.frame"),
48+
regexp = "The server-side object must be of type data.frame. 'x' is type list."
49+
)
50+
})
51+
52+
test_that(".checkClass() throws informative error for wrong class with three target classes", {
53+
x <- list(a = 1)
54+
expect_error(
55+
.checkClass(x, "x", c("data.frame", "matrix", "unicorn")),
56+
regexp = "The server-side object must be of type data.frame, matrix or unicorn. 'x' is type list."
57+
)
58+
})
59+
60+
test_that(".checkClass() throws informative error for three target classes and three actual classes", {
61+
x <- tibble(a = 1)
62+
expect_error(
63+
.checkClass(x, "x", c("Boolean", "unicorn", "donkey")),
64+
regexp = "The server-side object must be of type Boolean, unicorn or donkey. 'x' is type tbl_df, tbl and data.frame."
4965
)
5066
})
5167

0 commit comments

Comments
 (0)