You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jira@arrow.apache.org by "Neal Richardson (Jira)" <ji...@apache.org> on 2021/02/19 17:58:00 UTC

[jira] [Created] (ARROW-11700) [R] Internationalize error handling in tidy eval

Neal Richardson created ARROW-11700:
---------------------------------------

             Summary: [R] Internationalize error handling in tidy eval
                 Key: ARROW-11700
                 URL: https://issues.apache.org/jira/browse/ARROW-11700
             Project: Apache Arrow
          Issue Type: New Feature
          Components: R
            Reporter: Neal Richardson
            Assignee: Neal Richardson
             Fix For: 4.0.0


We have 

{code}
  tryCatch(eval_tidy(expr, mask), error = function(e) {
    # Look for the cases where bad input was given, i.e. this would fail
    # in regular dplyr anyway, and let those raise those as errors;
    # else, for things not supported by Arrow return a "try-error",
    # which we'll handle differently
    msg <- conditionMessage(e)
    # TODO: internationalization?
    if (grepl("object '.*'.not.found", msg)) {
      stop(e)
    }
    if (grepl('could not find function ".*"', msg)) {
      stop(e)
    }
    invisible(structure(msg, class = "try-error", condition = e))
  })
{code}

and tests for this behavior, but the tests are skipped because they only match correctly in an English locale because these base R messages are translated.

We can generate these regular expressions dynamically by triggering the R errors on a known nonexistent object:

{code}
> tryCatch(X_____X, error = function(e) conditionMessage(e))
[1] "object 'X_____X' not found"
> tryCatch(X_____X(), error = function(e) conditionMessage(e))
[1] "could not find function \"X_____X\""
> sub("X_____X", ".*", tryCatch(X_____X, error = function(e) conditionMessage(e)))
[1] "object '.*' not found"
{code}

And this will respect i18n:

{code}
> Sys.setenv(LANGUAGE="FR_fr")
> sub("X_____X", ".*", tryCatch(X_____X, error = function(e) conditionMessage(e)))
[1] "objet '.*' introuvable"
{code}





--
This message was sent by Atlassian Jira
(v8.3.4#803005)