Skip to content

Commit c25cf83

Browse files
Copilotkrlmlr
andauthored
chore: Ensure exported dm functions call check_dm() first (#2442)
Co-authored-by: krlmlr <1741643+krlmlr@users.noreply.github.com> Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
1 parent f87d021 commit c25cf83

5 files changed

Lines changed: 69 additions & 0 deletions

File tree

R/dm_wrap.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
#' dm_wrap_tbl(root = airlines)
4242
dm_wrap_tbl <- function(dm, root, strict = TRUE, progress = NA) {
4343
dm_local_error_call()
44+
check_dm(dm)
4445

4546
wrap_plan <- dm_wrap_tbl_plan(dm, {{ root }})
4647

R/draw-dm.R

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,7 @@ dm_get_all_column_types <- function(x) {
355355
#' @autoglobal
356356
dm_set_colors <- function(dm, ...) {
357357
dm_local_error_call()
358+
check_dm(dm)
358359
quos <- enquos(...)
359360
if (any(names(quos) == "")) {
360361
abort_only_named_args("dm_set_colors", "the colors")
@@ -414,6 +415,8 @@ color_quos_to_display <- function(...) {
414415
#' @rdname dm_set_colors
415416
#' @export
416417
dm_get_colors <- function(dm) {
418+
dm_local_error_call()
419+
check_dm(dm)
417420
dm %>%
418421
dm_get_def() %>%
419422
select(table, display) %>%

R/zoom.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ dm_update_zoomed <- function(dm) {
217217
#' @autoglobal
218218
dm_discard_zoomed <- function(dm) {
219219
dm_local_error_call()
220+
check_dm(dm)
220221
if (!is_zoomed(dm)) {
221222
return(dm)
222223
}

tests/testthat/_snaps/error-ownership.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,38 @@
102102
Error in `check_cardinality_0_1()`:
103103
! 0..1 cardinality (injectivity from child table to parent table) is not given: Column (`x`) in table child contains duplicate values.
104104

105+
# dm_set_colors() - abort_is_not_dm
106+
107+
Code
108+
dm_set_colors("not_a_dm", blue = a)
109+
Condition
110+
Error in `dm_set_colors()`:
111+
! Required class <dm> but instead is <character>.
112+
113+
# dm_get_colors() - abort_is_not_dm
114+
115+
Code
116+
dm_get_colors("not_a_dm")
117+
Condition
118+
Error in `dm_get_colors()`:
119+
! Required class <dm> but instead is <character>.
120+
121+
# dm_discard_zoomed() - abort_is_not_dm
122+
123+
Code
124+
dm_discard_zoomed("not_a_dm")
125+
Condition
126+
Error in `dm_discard_zoomed()`:
127+
! Required class <dm> but instead is <character>.
128+
129+
# dm_wrap_tbl() - abort_is_not_dm
130+
131+
Code
132+
dm_wrap_tbl("not_a_dm", root = a)
133+
Condition
134+
Error in `dm_wrap_tbl()`:
135+
! Required class <dm> but instead is <character>.
136+
105137
# dm_set_colors() - abort_only_named_args
106138

107139
Code

tests/testthat/test-error-ownership.R

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,38 @@ test_that("check_cardinality_0_1() - abort_not_injective", {
123123
})
124124
})
125125

126+
test_that("dm_set_colors() - abort_is_not_dm", {
127+
local_options(lifecycle_verbosity = "quiet")
128+
129+
expect_snapshot(error = TRUE, {
130+
dm_set_colors("not_a_dm", blue = a)
131+
})
132+
})
133+
134+
test_that("dm_get_colors() - abort_is_not_dm", {
135+
local_options(lifecycle_verbosity = "quiet")
136+
137+
expect_snapshot(error = TRUE, {
138+
dm_get_colors("not_a_dm")
139+
})
140+
})
141+
142+
test_that("dm_discard_zoomed() - abort_is_not_dm", {
143+
local_options(lifecycle_verbosity = "quiet")
144+
145+
expect_snapshot(error = TRUE, {
146+
dm_discard_zoomed("not_a_dm")
147+
})
148+
})
149+
150+
test_that("dm_wrap_tbl() - abort_is_not_dm", {
151+
local_options(lifecycle_verbosity = "quiet")
152+
153+
expect_snapshot(error = TRUE, {
154+
dm_wrap_tbl("not_a_dm", root = a)
155+
})
156+
})
157+
126158
test_that("dm_set_colors() - abort_only_named_args", {
127159
local_options(lifecycle_verbosity = "quiet")
128160

0 commit comments

Comments
 (0)