Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions r/adbcdrivermanager/R/error.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down
35 changes: 35 additions & 0 deletions r/adbcdrivermanager/tests/testthat/test-error.R
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
Loading