Skip to content

Commit 9f838f4

Browse files
CopilotkrlmlrCopilot
authored
refactor: replace all abort() with cli::cli_abort() (#2404)
Co-authored-by: krlmlr <1741643+krlmlr@users.noreply.github.com> Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: Kirill Müller <krlmlr@users.noreply.github.com> Co-authored-by: Copilot <Copilot@users.noreply.github.com>
1 parent 6b34483 commit 9f838f4

41 files changed

Lines changed: 393 additions & 103 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

R/build_copy_queries.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ build_copy_queries <- function(
3636
.x,
3737
"no_action" = "",
3838
"cascade" = " ON DELETE CASCADE",
39-
abort(glue('`on_delete = "{.x}"` not supported'))
39+
cli::cli_abort('{.code on_delete = {.val {.x}}} is not supported.')
4040
)
4141
}
4242
)

R/check-cardinalities.R

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,7 @@ check_card_api <- function(
257257
call = caller_env(),
258258
target = list
259259
) {
260+
dm_local_error_call(call)
260261
if (dots_n(...) >= 2) {
261262
name <- as.character(frame_call(call)[[1]] %||% "check_card_api")
262263
deprecate_warn(
@@ -315,8 +316,9 @@ check_card_api_impl <- function(
315316
if (!isTRUE(by_position)) {
316317
y_idx <- match(colnames(parent_table), colnames(child_table))
317318
if (anyNA(y_idx)) {
318-
abort(
319-
"`by_position = FALSE` or `by_position = NULL` require column names in `x` to match those in `y`."
319+
cli::cli_abort(
320+
"{.code by_position = FALSE} or {.code by_position = NULL} require column names in {.arg x} to match those in {.arg y}.",
321+
call = dm_error_call()
320322
)
321323
}
322324

R/db-interface.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ db_append_table <- function(
299299
# Can't use dbAppendTable(): https://github.com/r-dbi/odbc/issues/480
300300
sql <- DBI::sqlAppendTable(con, remote_table_id, values, row.names = FALSE)
301301
if (length(autoinc) > 1L) {
302-
abort("more than one autoincrement key in one table")
302+
cli::cli_abort("More than one autoincrement key in one table.")
303303
}
304304
if (!is_empty(autoinc) && autoinc) {
305305
sql <- DBI::SQL(paste0(

R/deconstruct.R

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -309,17 +309,23 @@ keyed_by <- function(x, y) {
309309
fks_df <- fks_df_from_keys_info(list(x = x, y = y))
310310

311311
if (nrow(fks_df) == 0) {
312-
abort("Can't infer `by`: foreign key information lost?")
312+
cli::cli_abort("Can't infer {.arg by}: foreign key information lost?", call = dm_error_call())
313313
}
314314

315315
stopifnot(map_int(fks_df$fks, NROW) > 0)
316316

317317
if (nrow(fks_df) > 1) {
318-
abort("Can't infer `by`: foreign key available in both directions")
318+
cli::cli_abort(
319+
"Can't infer {.arg by}: foreign key available in both directions.",
320+
call = dm_error_call()
321+
)
319322
}
320323

321324
if (nrow(fks_df$fks[[1]]) > 1) {
322-
abort("Can't infer `by`: multiple foreign keys available")
325+
cli::cli_abort(
326+
"Can't infer {.arg by}: multiple foreign keys available.",
327+
call = dm_error_call()
328+
)
323329
}
324330

325331
fk <- fks_df$fks[[1]][1, ]

R/dm.R

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,15 @@ dm <- function(
6363

6464
for (i in which(is_dm)) {
6565
if (names[[i]] != "") {
66-
abort(c(
67-
"All dm objects passed to `dm()` must be unnamed.",
66+
cli::cli_abort(c(
67+
"All dm objects passed to {.fun dm} must be unnamed.",
6868
i = paste0("Argument ", i, " has name ", tick(names[[i]]), ".")
6969
))
7070
}
7171

7272
if (is_zoomed(dots[[i]])) {
73-
abort(c(
74-
"All dm objects passed to `dm()` must be unzoomed.",
73+
cli::cli_abort(c(
74+
"All dm objects passed to {.fun dm} must be unzoomed.",
7575
i = paste0("Argument ", i, " is a zoomed dm.")
7676
))
7777
}
@@ -313,7 +313,7 @@ as_dm.default <- function(x, ...) {
313313
check_dots_empty()
314314

315315
if (!is.list(x) || is.object(x)) {
316-
abort(paste0("Can't coerce <", class(x)[[1]], "> to <dm>."))
316+
cli::cli_abort("Can't coerce {.cls {class(x)[[1]]}} to {.cls dm}.")
317317
}
318318

319319
# Automatic name repair
@@ -699,7 +699,7 @@ src_tbls_impl <- function(dm, quiet = FALSE) {
699699
#' class()
700700
compute.dm <- function(x, ..., temporary = TRUE) {
701701
if (!isTRUE(temporary)) {
702-
abort("`compute.dm()` does not support `temporary = FALSE`.")
702+
cli::cli_abort("{.fun compute.dm} does not support {.code temporary = FALSE}.")
703703
}
704704

705705
# for both dm and dm_zoomed
@@ -842,12 +842,16 @@ pull_tbl.dm <- function(dm, table, ..., keyed = FALSE) {
842842

843843
#' @export
844844
pull_tbl.dm_zoomed <- function(dm, table, ..., keyed = FALSE) {
845+
dm_local_error_call()
846+
845847
if (isTRUE(keyed)) {
846-
abort("`keyed = TRUE` not supported for zoomed dm objects.")
848+
cli::cli_abort(
849+
"{.code keyed = TRUE} not supported for zoomed dm objects.",
850+
call = dm_error_call()
851+
)
847852
}
848853

849854
check_dots_empty()
850-
dm_local_error_call()
851855

852856
table_name <- as_string(enexpr(table))
853857
zoomed <- dm_get_zoom(dm)

R/dm_nest_tbl.R

Lines changed: 28 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
#'
2626
#' nested_dm$airlines
2727
dm_nest_tbl <- function(dm, child_table, into = NULL) {
28+
dm_local_error_call()
29+
2830
# process args
2931
into <- enquo(into)
3032
# FIXME: Rename table_name to child_tables_name
@@ -52,27 +54,24 @@ dm_nest_tbl <- function(dm, child_table, into = NULL) {
5254

5355
# make sure we have a terminal child
5456
if (length(children) || !length(parent_name) || length(parent_name) > 1) {
55-
if (length(parent_name)) {
56-
parent_msg <- paste0("\nparents: ", toString(paste0("`", parent_name, "`")))
57-
} else {
58-
parent_msg <- ""
59-
}
60-
if (length(children)) {
61-
children_msg <- paste0("\nchildren: ", toString(paste0("`", children, "`")))
62-
} else {
63-
children_msg <- ""
64-
}
65-
abort(glue(
66-
"`{table_name}` can't be nested because it is not a terminal child table.",
67-
"{parent_msg}{children_msg}"
68-
))
57+
cli::cli_abort(
58+
c(
59+
"{.val {table_name}} can't be nested because it is not a terminal child table.",
60+
if (length(parent_name)) "parents: {.val {parent_name}}",
61+
if (length(children)) "children: {.val {children}}"
62+
),
63+
call = dm_error_call()
64+
)
6965
}
7066

7167
# check consistency of `into` if relevant
7268
if (!quo_is_null(into)) {
7369
into <- dm_tbl_name(dm, !!into)
7470
if (into != parent_name) {
75-
abort(glue("`{table_name}` can only be packed into `{child_name}`"))
71+
cli::cli_abort(
72+
"{.val {table_name}} can only be packed into {.val {child_name}}.",
73+
call = dm_error_call()
74+
)
7675
}
7776
}
7877

@@ -126,6 +125,8 @@ dm_nest_tbl <- function(dm, child_table, into = NULL) {
126125
#'
127126
#' dm_packed$flights$planes
128127
dm_pack_tbl <- function(dm, parent_table, into = NULL) {
128+
dm_local_error_call()
129+
129130
# process args
130131
into <- enquo(into)
131132
table_name <- dm_tbl_name(dm, {{ parent_table }})
@@ -147,7 +148,10 @@ dm_pack_tbl <- function(dm, parent_table, into = NULL) {
147148
if (!quo_is_null(into)) {
148149
into <- dm_tbl_name(dm, !!into)
149150
if (into != child_name) {
150-
abort(glue("`{table_name}` can only be packed into `{child_name}`"))
151+
cli::cli_abort(
152+
"{.val {table_name}} can only be packed into {.val {child_name}}.",
153+
call = dm_error_call()
154+
)
151155
}
152156
}
153157

@@ -181,21 +185,14 @@ check_table_can_be_packed <- function(table_name, children_names, fks) {
181185
table_has_one_child <- length(children_names) == 1
182186
table_is_terminal_parent <- table_has_one_child && !table_has_parents
183187
if (!table_is_terminal_parent) {
184-
if (table_has_parents) {
185-
parent_msg <- paste0("\nparents : ", toString(paste0("`", parents, "`")))
186-
} else {
187-
parent_msg <- ""
188-
}
189-
table_has_children <- length(children_names) > 0
190-
if (table_has_children) {
191-
children_msg <- paste0("\nchildren: ", toString(paste0("`", children_names, "`")))
192-
} else {
193-
children_msg <- ""
194-
}
195-
abort(glue(
196-
"`{table_name}` can't be packed because it is not a terminal parent table.",
197-
"{parent_msg}{children_msg}"
198-
))
188+
cli::cli_abort(
189+
c(
190+
"{.val {table_name}} can't be packed because it is not a terminal parent table.",
191+
if (length(parents) > 0) "parents : {.val {parents}}",
192+
if (length(children_names) > 0) "children: {.val {children_names}}"
193+
),
194+
call = dm_error_call()
195+
)
199196
}
200197
invisible(NULL)
201198
}

R/dm_sql.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ ddl_get_fk_defs <- function(fks, con, table_names) {
487487
.x,
488488
"no_action" = "",
489489
"cascade" = " ON DELETE CASCADE",
490-
abort(glue('`on_delete = "{.x}"` not supported'))
490+
cli::cli_abort('{.code on_delete = {.val {.x}}} is not supported.')
491491
)
492492
}
493493
)

R/dm_wrap.R

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040
#' dm_nycflights13() %>%
4141
#' dm_wrap_tbl(root = airlines)
4242
dm_wrap_tbl <- function(dm, root, strict = TRUE, progress = NA) {
43+
dm_local_error_call()
44+
4345
wrap_plan <- dm_wrap_tbl_plan(dm, {{ root }})
4446

4547
ticker <- new_ticker(
@@ -60,7 +62,10 @@ dm_wrap_tbl <- function(dm, root, strict = TRUE, progress = NA) {
6062
if (length(wrapped_dm) > 1) {
6163
if (strict) {
6264
# FIXME: Detect earlier
63-
abort("The `dm` is not cycle free and can't be wrapped into a single tibble.")
65+
cli::cli_abort(
66+
"The {.cls dm} is not cycle free and can't be wrapped into a single tibble.",
67+
call = dm_error_call()
68+
)
6469
}
6570
}
6671

R/financial-db-con.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
#' @noRd
66
financial_db_con <- function() {
77
if (Sys.getenv("DM_OFFLINE") != "") {
8-
abort("Offline")
8+
cli::cli_abort("Offline")
99
}
1010

1111
err_relational <- tryCatch(return(relational_con()), error = identity)
1212
err_dbedu <- tryCatch(return(dbedu_con()), error = identity)
1313

14-
abort(paste0(
14+
cli::cli_abort(paste0(
1515
"Can't connect to relational.fel.cvut.cz or databases.pacha.dev:\n",
1616
conditionMessage(err_relational),
1717
"\n",

R/gui-check.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@ check_tbl_in_dm <- function(
1919

2020
check_at_least_one_col <- function(cols, call = current_call()) {
2121
if (length(cols) < 1) {
22-
abort("Hey, you should select at least one column!", call = call)
22+
cli::cli_abort("At least one column must be selected.", call = call)
2323
}
2424
}

0 commit comments

Comments
 (0)