diff --git a/r/adbcdrivermanager/R/error.R b/r/adbcdrivermanager/R/error.R index a7c3eeb8d8..5d9aadeed6 100644 --- a/r/adbcdrivermanager/R/error.R +++ b/r/adbcdrivermanager/R/error.R @@ -75,6 +75,11 @@ stop_for_error <- function(status, error) { # Store the listified error information cnd$error <- error + # Always temporarily raise warning.length to its maximum so driver manager + # errors don't get truncated + old_options <- options(warning.length = 8170L) + on.exit(options(old_options), add = TRUE) + stop(cnd) } } diff --git a/r/adbcdrivermanager/tests/testthat/test-error.R b/r/adbcdrivermanager/tests/testthat/test-error.R index afffa241e4..ce8912c053 100644 --- a/r/adbcdrivermanager/tests/testthat/test-error.R +++ b/r/adbcdrivermanager/tests/testthat/test-error.R @@ -41,6 +41,33 @@ test_that("error allocator works", { expect_identical(err$details, setNames(list(), character())) }) +test_that("stop_for_error() does not truncate long error messages", { + # Long messages (e.g., the list of paths searched for a driver manifest) + # should not be cut off at the default warning.length of 1000 characters + old_options <- options(warning.length = 1000L) + on.exit(options(old_options)) + + warning_length_while_signalled <- NULL + had_error <- FALSE + tryCatch( + withCallingHandlers( + adbc_driver(paste0("not_a_driver_", strrep("x", 1000))), + adbc_status = function(e) { + warning_length_while_signalled <<- getOption("warning.length") + } + ), + adbc_status = function(e) { + had_error <<- TRUE + expect_gt(nchar(conditionMessage(e), type = "bytes"), 1000) + } + ) + + expect_true(had_error) + expect_identical(warning_length_while_signalled, 8170L) + # The option is restored after the error was signalled + expect_identical(getOption("warning.length"), 1000L) +}) + test_that("stop_for_error() gives a custom error class with extra info", { had_error <- FALSE tryCatch({