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

Could not parse cli {} expression #254

Closed
aculham opened this issue May 13, 2023 · 4 comments · Fixed by #255
Closed

Could not parse cli {} expression #254

aculham opened this issue May 13, 2023 · 4 comments · Fixed by #255

Comments

@aculham
Copy link

aculham commented May 13, 2023

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
Copy link
Member

jennybc commented May 13, 2023

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
Copy link
Author

aculham commented May 13, 2023

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
Copy link
Member

jennybc commented May 13, 2023

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
Copy link
Author

aculham commented May 14, 2023

I sent you an email.

jennybc added a commit that referenced this issue May 17, 2023
…255)

* General modernization of some errors; better handling of HTML error

Fixes #254

* Use a bullet

* Whitespace

* More internal consistency

Seems weird to have a mix of parent.frame() and caller_env(), so prefer the latter.

* Re-document()

* Possibly safer

Content type might look like `"text/html; charset=UTF-8"` (even though httr seems to just return `"text/html"` in that case)

* Add a snapshot test

* Style

* Add a test to surface the actual html

* NEWS bullets
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants