Skip to content
Open
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
27 changes: 27 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,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))),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably best to bump this down so it's always a valid filename.

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