Uploaded image for project: 'Apache Arrow'
  1. Apache Arrow
  2. ARROW-11700

[R] Internationalize error handling in tidy eval

    XMLWordPrintableJSON

Details

    • New Feature
    • Status: Resolved
    • Minor
    • Resolution: Fixed
    • None
    • 4.0.0
    • R

    Description

      We have

        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))
        })
      

      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:

      > 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"
      

      And this will respect i18n:

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

      Attachments

        Issue Links

          Activity

            People

              npr Neal Richardson
              npr Neal Richardson
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 50m
                  50m