r-lib / gargle

Infrastructure for calling Google APIs from R, including auth
https://gargle.r-lib.org/
Other
113 stars 33 forks source link

Could not parse cli `{}` expression #254

Closed aculham closed 1 year ago

aculham commented 1 year ago

In the last couple of days I have started to see some transient errors upon uploading a file to Google Drive via the googledrive package. The errors seem to be originating in the gargle package, which is why I am posting this here. Unfortunately, I cannot provide a reproducible example since the error doesn't happen every time. I am unable to identify any pattern in when it fails or doesn't. Below is the error and traceback. Any advice would be appreciated.

Error in `fun(..., .envir = .envir)`:
! Could not parse cli `{}` expression: ` font-family: ver...`.
Caused by error in `parse(text = code, keep.source = FALSE)`:
! <text>:1:22: unexpected ','
1:  font-family: verdana,
                         ^
Type .Last.error to see the more details.
Backtrace:
 1. global upload_drive_file("C:\\temp.7z", "Data")
 2. googledrive::drive_upload(file_path, path = id, overwrite = overwrite) at google_drive.R:89:5
 3. googledrive::as_dribble(list(gargle::response_process(response)))
 4. gargle::response_process(response)
 5. gargle:::gargle_abort_request_failed(error_message(resp), resp)
 6. gargle:::gargle_abort(message, class = c("gargle_error_request_failed", ...
 7. cli::cli_abort(message, class = c(class, "gargle_error"), .envir = .envir, ...
 8. cli:::vcapply(message, format_inline, .envir = .envir)
 9. base::vapply(X, FUN, FUN.VALUE = character(1), ..., USE.NAMES = USE.NAMES)
10. local error_message(resp)
11. gargle::response_as_json(resp)
12. gargle:::check_for_json(resp)
13. gargle:::gargle_abort_request_failed(c(gargle_map_cli(type, template = "Expected content type {.field application/json}, not \\\n                    {.field <<x>>}."), ...
14. gargle:::gargle_abort(message, class = c("gargle_error_request_failed", ...
15. cli::cli_abort(message, class = c(class, "gargle_error"), .envir = .envir, ...
16. cli:::vcapply(message, format_inline, .envir = .envir)
17. base::vapply(X, FUN, FUN.VALUE = character(1), ..., USE.NAMES = USE.NAMES)
18. local FUN(X[[i]], ...)
19. cli::cli_fmt(fun(..., .envir = .envir), collapse = collapse, strip_newline = TRUE)
20. cli:::cli__rec(expr)
21. local fun(..., .envir = .envir)
22. cli:::cli__message("inline_text", list(text = glue_cmd(..., .envir = .envir, ...
23. "id" %in% names(args)
24. cli:::glue_cmd(..., .envir = .envir, .call = sys.call(), .trim = FALSE)
25. cli:::glue(str, .envir = .envir, .transformer = transformer, .cli = TRUE, ...
26. (function (expr) ...
27. .transformer(expr, .envir) %||% character()
28. local .transformer(expr, .envir)
29. parse(text = code, keep.source = FALSE) %??% cli_error(call. = caller, ...
30. cli:::chain_error(expr, err, srcref = utils::getSrcref(sys.call()))
31. | base::withCallingHandlers({ ...
32. base::parse(text = code, keep.source = FALSE)
33. base::.handleSimpleError(function (e) ...
34. | local h(simpleError(msg, call))
35. | cli:::throw_error(err, parent = e)
jennybc commented 1 year ago

It's hard to say exactly what's going on. But it sort of looks like the upload was unsuccessful AND the attempt to message informatively about that is erroring. So possibly an error while throwing an error.

When this happen, has the upload worked? I suspect not.

Right after this happens gargle should have the last response stored internally available via gargle:::gargle_last_response() (note the triple colons, this is not an exported function). That should allow you to fully inspect the response and see why the upload failed (which is my hypothesis). Then there's the matter of figuring out why the intended error handling is not working.

Hopefully this gets you started on some troubleshooting.

I would also double check that you are using the most recent CRAN versions of all relevant packages (gargle and cli and googledrive, most especially).

aculham commented 1 year ago

Thank you for your comment, it was very helpful. Using gargle:::gargle_last_response() allowed me to see that I am getting a Status 429 error which means I have sent too many requests. I think this also explains why the issue is transient and not reproducible. I don't understand why I am getting that error, but that is not a problem in the package.

jennybc commented 1 year ago

Well, we should still be surfacing that error properly. If you would be willing to send me the error object (to my maintainer email), I'd be very interested in inspecting it and figuring out how it violates our expectations and fixing that.

aculham commented 1 year ago

I sent you an email.