This is an automated email from the ASF dual-hosted git repository.

amoeba pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow-adbc.git


The following commit(s) were added to refs/heads/main by this push:
     new 6d3a89655f fix(r/adbcdrivermanager): don't truncate long error 
messages (#4939)
6d3a89655f is described below

commit 6d3a89655f4688e5dc81b156c7d38d35632d3e5d
Author: ump45nose <[email protected]>
AuthorDate: Thu Nov 19 23:40:19 2026 +0800

    fix(r/adbcdrivermanager): don't truncate long error messages (#4939)
    
    Closes #3450.
    
    R truncates the printed message of an uncaught error to
    `getOption("warning.length")` characters, which is 1000 by default.
    Driver manager errors can easily be longer than that, for example when a
    driver isn't found and the message lists every `dlopen()` attempt and
    every path searched for manifests, so the end of the message (the part
    listing the manifest search paths) gets cut off in R while Python shows
    all of it.
    
    `stop_for_error()` now raises `warning.length` to its maximum (8170)
    while it signals the condition, but only when the message is longer than
    the current limit. The option is restored via `on.exit()` once `stop()`
    unwinds, so the user's setting is left unchanged. The condition object
    itself was never truncated (`conditionMessage(e)` already had the full
    text); this only affects what is printed.
    
    This PR was prepared with AI assistance.
    
    ---------
    
    Signed-off-by: Vincent <[email protected]>
---
 r/adbcdrivermanager/R/error.R                   |  5 ++++
 r/adbcdrivermanager/tests/testthat/test-error.R | 35 +++++++++++++++++++++++++
 2 files changed, 40 insertions(+)

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..69cc36dd36 100644
--- a/r/adbcdrivermanager/tests/testthat/test-error.R
+++ b/r/adbcdrivermanager/tests/testthat/test-error.R
@@ -41,6 +41,41 @@ 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))
+
+  # The long message comes from the driver search paths, which the error lists
+  # in full, rather than from an over-long filename component: a name over 255
+  # bytes is not a filename that any filesystem accepts.
+  search_dirs <- file.path(tempdir(), paste0(strrep("s", 200), seq_len(6)))
+
+  warning_length_while_signalled <- NULL
+  had_error <- FALSE
+  withr::with_envvar(
+    list(ADBC_DRIVER_PATH = paste(search_dirs, collapse = .Platform$path.sep)),
+    tryCatch(
+      withCallingHandlers(
+        adbc_driver("not_a_driver"),
+        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({

Reply via email to