Skip to content
Merged
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
7 changes: 5 additions & 2 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
# gargle (development version)

* Fixed a bug when displaying a request failure that includes a localized
message in the error details (#293).
* Fixed some bugs around surfacing the details of a request failure:
- Better handling when the error details include a localized message (#293)
- Defensive escaping of `{..}` in Google-provided error messages, to prevent
`cli::cli_abort()` from trying (and failing) to do string interpolation
(https://github.com/tidyverse/googlesheets4/issues/319)
* gargle is better able to detect when it's running on Posit Workbench, but not
necessarily in RStudio, such as in Positron or VS Code (#291).

Expand Down
22 changes: 18 additions & 4 deletions R/response_process.R
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ gargle_error_message <- function(resp, call = caller_env()) {
"*" = content$error,
"*" = content$error_description
)
return(message)
return(escape_braces(message))
}

if (is.null(error)) {
Expand All @@ -174,7 +174,7 @@ gargle_error_message <- function(resp, call = caller_env()) {
httr::http_status(resp)$message,
"*" = content$error_description
)
return(message)
return(escape_braces(message))
}
errors <- error[["errors"]]

Expand All @@ -190,7 +190,7 @@ gargle_error_message <- function(resp, call = caller_env()) {

error_details <- error$details
if (is.null(error_details)) {
return(message)
return(escape_braces(message))
}

# https://github.com/googleapis/googleapis/blob/master/google/rpc/error_details.proto
Expand Down Expand Up @@ -219,7 +219,7 @@ gargle_error_message <- function(resp, call = caller_env()) {
"",
reveal_details(error_details)
)
return(message)
return(escape_braces(message))
}

# developed from
Expand Down Expand Up @@ -371,3 +371,17 @@ gargle_html_error_message <- function(resp) {
)
)
}

# Google APIs might return error messages containing curly braces, e.g.
# "metadata.quota_unit: 1/min/{project}/{user}"
# This can cause problems when eventually process by cli::cli_abort(), e.g.
# Error:
# ! ! Could not evaluate cli `{}` expression: `project`.
# Caused by error in `eval(expr, envir = envir)`:
# ! object 'project' not found
# So we need to escape them by doubling them, so they are taken literally.
# Seen by me and by a user:
# https://github.com/tidyverse/googlesheets4/issues/319
escape_braces <- function(msg) {
gsub("([{}])", "\\1\\1", msg)
}
9 changes: 5 additions & 4 deletions tests/testthat/_snaps/response_process.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,16 @@
Error details:
* reason: RATE_LIMIT_EXCEEDED
* domain: googleapis.com
* metadata.quota_limit_value: 60
* metadata.service: sheets.googleapis.com
* metadata.consumer: projects/603366585132
* metadata.quota_unit: 1/min/{project}/{user}
* metadata.quota_location: global
* metadata.quota_metric: sheets.googleapis.com/read_requests
* metadata.quota_limit: ReadRequestsPerMinutePerUser
* metadata.quota_limit_value: 60
* metadata.consumer: projects/603366585132
* metadata.service: sheets.googleapis.com
Links
* Description: Request a higher quota limit.
URL: https://cloud.google.com/docs/quota#requesting_higher_quota
URL: https://cloud.google.com/docs/quotas/help/request_increase

# Request for non-existent resource (Drive)

Expand Down
Binary file not shown.
Loading