diff --git a/R/db-io.R b/R/db-io.R index 7dcdfba47..16e1c12a4 100644 --- a/R/db-io.R +++ b/R/db-io.R @@ -184,7 +184,7 @@ db_write_table.DBIConnection <- function(con, check_bool(temporary) check_bool(overwrite) - tryCatch( + withCallingHandlers( dbWriteTable( con, name = table_ident_to_id(table), diff --git a/R/db-sql.R b/R/db-sql.R index c5787f6e8..894d738a9 100644 --- a/R/db-sql.R +++ b/R/db-sql.R @@ -1065,7 +1065,7 @@ db_analyze.DBIConnection <- function(con, table, ...) { if (is.null(sql)) { return() # nocov } - tryCatch( + withCallingHandlers( DBI::dbExecute(con, sql), error = function(cnd) { msg <- "Can't analyze table {.field {format(table, con = con)}}." @@ -1086,7 +1086,7 @@ db_create_index.DBIConnection <- function(con, unique = FALSE, ...) { sql <- sql_table_index(con, table, columns, name = name, unique = unique, ...) - tryCatch( + withCallingHandlers( DBI::dbExecute(con, sql), error = function(cnd) { msg <- "Can't create index on table {.field {format(table, con = con)}}." @@ -1103,10 +1103,9 @@ dbplyr_explain <- function(con, ...) { db_explain.DBIConnection <- function(con, sql, ...) { sql <- sql_query_explain(con, sql, ...) call <- current_call() - tryCatch( - { - expl <- DBI::dbGetQuery(con, sql) - }, error = function(cnd) { + expl <- withCallingHandlers( + DBI::dbGetQuery(con, sql), + error = function(cnd) { cli_abort("Can't explain query.", parent = cnd) } ) @@ -1122,10 +1121,9 @@ dbplyr_query_fields <- function(con, ...) { #' @importFrom dplyr db_query_fields db_query_fields.DBIConnection <- function(con, sql, ...) { sql <- sql_query_fields(con, sql, ...) - tryCatch( - { - df <- DBI::dbGetQuery(con, sql) - }, error = function(cnd) { + df <- withCallingHandlers( + DBI::dbGetQuery(con, sql), + error = function(cnd) { cli_abort("Can't query fields.", parent = cnd) } ) @@ -1144,7 +1142,7 @@ db_save_query.DBIConnection <- function(con, ..., overwrite = FALSE) { sql <- sql_query_save(con, sql, name, temporary = temporary, ...) - tryCatch( + withCallingHandlers( { if (overwrite) { name <- as_table_ident(name) @@ -1155,8 +1153,12 @@ db_save_query.DBIConnection <- function(con, } } DBI::dbExecute(con, sql, immediate = TRUE) - }, error = function(cnd) { - cli_abort("Can't save query to table {.table {format(name, con = con)}}.", parent = cnd) + }, + error = function(cnd) { + cli_abort( + "Can't save query to table {.table {format(name, con = con)}}.", + parent = cnd + ) } ) name diff --git a/R/rows.R b/R/rows.R index 7b1b15f2f..9655e470b 100644 --- a/R/rows.R +++ b/R/rows.R @@ -760,8 +760,7 @@ rows_auto_copy <- function(x, y, copy, call = caller_env()) { rows_get_or_execute <- function(x, sql, returning_cols, call = caller_env()) { con <- remote_con(x) - msg <- "Can't modify database table {.val {remote_name(x)}}." - tryCatch( + withCallingHandlers( { if (is_empty(returning_cols)) { DBI::dbExecute(con, sql, immediate = TRUE) @@ -771,7 +770,11 @@ rows_get_or_execute <- function(x, sql, returning_cols, call = caller_env()) { } }, error = function(cnd) { - cli_abort(msg, parent = cnd, call = call) + cli_abort( + "Can't modify database table {.val {remote_name(x)}}.", + parent = cnd, + call = call + ) } ) diff --git a/R/verb-compute.R b/R/verb-compute.R index 1303e82b8..6fe53787a 100644 --- a/R/verb-compute.R +++ b/R/verb-compute.R @@ -128,8 +128,8 @@ collect.tbl_sql <- function(x, ..., n = Inf, warn_incomplete = TRUE, cte = FALSE } sql <- db_sql_render(x$src$con, x, cte = cte) - tryCatch( - out <- db_collect(x$src$con, sql, n = n, warn_incomplete = warn_incomplete, ...), + out <- withCallingHandlers( + db_collect(x$src$con, sql, n = n, warn_incomplete = warn_incomplete, ...), error = function(cnd) { cli_abort("Failed to collect lazy table.", parent = cnd) }