Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: teal.logger error handler will fail when string has {...} #101

Open
3 tasks done
averissimo opened this issue Nov 25, 2024 · 0 comments
Open
3 tasks done

[Bug]: teal.logger error handler will fail when string has {...} #101

averissimo opened this issue Nov 25, 2024 · 0 comments
Labels
bug Something isn't working core

Comments

@averissimo
Copy link
Contributor

averissimo commented Nov 25, 2024

What happened?

Problem

Errors thrown within packages (let's say teal.modules.general) will throw a different error from {glue}

How to reproduce

Reproducible code, but not generatable from reprex.

The idea is to have a function inside pkgX that throws an error where the message contains { ... }.

This is the case for checkmate::assert_names

library(teal.logger)
fun <- function(arr, permutation.of = c("a", "b")) {
  checkmate::assert_names(names(arr), permutation.of = permutation.of)
}
environment(fun) <- environment(register_handlers)

register_handlers("teal.logger")
fun(list(b = 1, c = 2))
#> Error in (function (e)  : `glue` failed in `formatter_glue` on:
#> 
#>  chr "In ‘fun(list(b = 1, c = 2))’: Assertion on 'names(arr)' failed: Names must be a permutation of set {'a','b'}, b"| __truncated__
#> 
#> Raw error message:
#> 
#> Failed to parse glue component
#> Caused by error in `parse()`:
#> ! <text>:1:4: unexpected ','
#> 1: 'a',
#>        ^
#> 
#> Please consider using another `log_formatter` or `skip_formatter` on strings with curly braces.
checkmate::assert_names(names(list(b = 1, c = 2)), permutation.of = c("a", "b"))

Possible solution

Hint logger to skip formating, this can be done as below or in parse_logger_message function

diff --git a/R/register_handlers.R b/R/register_handlers.R
index 930d341..ef3a6fa 100644
--- a/R/register_handlers.R
+++ b/R/register_handlers.R
@@ -87,7 +87,7 @@ register_handler_type <- function(
         msg <- parse_logger_message(m)
 
         log_namespace <- registered_handlers_namespaces[[pkg_sys_fun_i]]
-        logger_fun(msg, namespace = log_namespace)
+        logger_fun(structure(msg, skip_formatter = TRUE), namespace = log_namespace)
 
         # muffle restart
         if (isTRUE(as.logical(get_val("TEAL.LOG_MUFFLE", "teal.log_muffle", TRUE)))) {

sessionInfo()

No response

Relevant log output

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct.

Contribution Guidelines

  • I agree to follow this project's Contribution Guidelines.

Security Policy

  • I agree to follow this project's Security Policy.
@averissimo averissimo added bug Something isn't working core labels Nov 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working core
Projects
None yet
Development

No branches or pull requests

1 participant