Skip to content

Commit 536bc50

Browse files
authored
fix logger error All unnamed arguments must be length 1. (#103)
`glue` fails when receives a vector of length > 1. Message generate with warning could have n-elements and `parse_logger_message` would return a vector instead of a single character. Example ```r teal.logger::register_logger("teal.code") teal.logger::register_handlers("teal.code") teal.code::qenv() |> within(a <- 1) |> teal.code::get_var("a") # Error in h(simpleError(msg, call)) : # `glue` failed in `formatter_glue` on: # # Named chr [1:2] "`get_var()` was deprecated in teal.code 0.5.1." "Please use `base::get()` instead." # - attr(*, "names")= chr [1:2] "" "i" # # Raw error message: # # All unnamed arguments must be length 1 # # Please consider using another `log_formatter` or `skip_formatter` on strings with curly braces. ```
1 parent 1838b74 commit 536bc50

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

R/register_handlers.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ parse_logger_message <- function(m) {
129129
if (type %in% c("error", "warning") && !is.null(m$call)) {
130130
msg <- sprintf("In %s: %s", sQuote(paste0(format(m$call), collapse = "")), msg)
131131
}
132-
return(msg)
132+
return(paste(msg, collapse = "\n"))
133133
}
134134

135135
register_handlers_possible <- function() {

tests/testthat/test-register_handlers.R

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
testthat::test_that("parse_logger_message correctly works on condition object", {
2-
testthat::expect_identical(parse_logger_message(simpleMessage("foo")), "foo")
3-
testthat::expect_identical(parse_logger_message(simpleWarning("foo")), "foo")
4-
testthat::expect_identical(parse_logger_message(simpleError("foo")), "foo")
2+
testthat::expect_identical(parse_logger_message(simpleMessage(message = "foo")), "foo")
3+
testthat::expect_identical(parse_logger_message(simpleWarning(message = "foo")), "foo")
4+
testthat::expect_identical(parse_logger_message(simpleError(message = "foo")), "foo")
5+
})
6+
7+
testthat::test_that("parse_logger_message concatenates n-element message", {
8+
testthat::expect_identical(parse_logger_message(simpleMessage(message = c("foo1", "foo2"))), "foo1\nfoo2")
9+
testthat::expect_identical(parse_logger_message(simpleWarning(message = c("foo1", "foo2"))), "foo1\nfoo2")
10+
testthat::expect_identical(parse_logger_message(simpleError(message = c("foo1", "foo2"))), "foo1\nfoo2")
511
})
612

713
testthat::test_that("parse_logger_message includes call on warnings and errors", {
8-
testthat::expect_match(parse_logger_message(simpleWarning("foo", "bar")), "In .bar.: foo")
9-
testthat::expect_match(parse_logger_message(simpleError("foo", "bar")), "In .bar.: foo")
14+
testthat::expect_match(parse_logger_message(simpleWarning(message = "foo", call = "bar")), "In .bar.: foo")
15+
testthat::expect_match(parse_logger_message(simpleError(message = "foo", call = "bar")), "In .bar.: foo")
1016
})
1117

1218
testthat::test_that("parse_logger_message throws if not supported class of argument", {

0 commit comments

Comments
 (0)