Skip to content

googlesheets4 call fails with object 'project' not found in way that tryCatch fails #319

Description

@alcrosby

I'm running a process that updates a variety of sheets for a student information / data collection project for a school district. It loops through a series of grades at a series of schools, reading data from a set of sheets, doing some minimal processing, copying a blank template sheet, and re-writing the data.

Occasionally, Google times out. I've surrounded code with tryCatch, which helps, but sometimes I get an error like the one below that fails in a way tryCatch doesn't see and allow me to perform error handling.

I assume it's caused by Google being 'busy' or taking too long to process a specific request, but it would be nice if error handling could catch it reasonably gracefully.

✖ Request failed [429]. Retry 4 happens in 41.9 seconds ...
Error in `fun(..., .envir = .envir)`:
! Could not evaluate cli `{}` expression: `project`.
Caused by error in `eval(expr, envir = envir)`:
! object 'project' not found
Type .Last.error to see the more details.
> .Last.error
<rlib_error_3_0/rlib_error/error>
Error in `fun(..., .envir = .envir)`:
! Could not evaluate cli `{}` expression: `project`.
Caused by error in `eval(expr, envir = envir)`:
! object 'project' not found
---
Backtrace:
 1. base::tryCatch(update_dibels_students(b, g, parent_folder = dibels_parent_folder, …
 2. base::tryCatchList(expr, classes, parentenv, handlers)
 3. global update_dibels_students(b, g, parent_folder = dibels_parent_folder, …
 4. googlesheets4::gs4_get(working_sheet) at localfunctions.r:130:5
 5. googlesheets4:::gs4_get_impl_(as_sheets_id(ss))
 6. gargle::response_process(raw_resp)
 7. gargle:::gargle_abort_request_failed(error_message(resp, call = call), …
 8. gargle:::gargle_abort(message, class = c("gargle_error_request_failed", …
 9. cli::cli_abort(message, class = c(class, "gargle_error"), .envir = .envir, …
10. cli:::vcapply(message, format_inline, .envir = .envir)
11. base::vapply(X, FUN, FUN.VALUE = character(1), ..., USE.NAMES = USE.NAMES)
12. local FUN(X[[i]], ...)
13. cli::cli_fmt(fun(..., .envir = .envir), collapse = collapse, strip_newline = TRUE)
14. cli:::cli__rec(expr)
15. local fun(..., .envir = .envir)
16. cli:::cli__message("inline_text", list(text = glue_cmd(..., .envir = .envir, …
17. "id" %in% names(args)
18. cli:::glue_cmd(..., .envir = .envir, .call = sys.call(), .trim = FALSE)
19. cli:::glue(str, .envir = .envir, .transformer = transformer, .cli = TRUE, …
20. (function (expr) …
21. .transformer(expr, .envir) %||% character()
22. local .transformer(expr, .envir)
23. eval(expr, envir = envir) %??% cli_error(call. = caller, "Could not evaluate cli {.c…
24. cli:::chain_error(expr, err, srcref = utils::getSrcref(sys.call()))
25. | base::withCallingHandlers({ …
26. base::eval(expr, envir = envir)
27. base::eval(expr, envir = envir)
28. base::.handleSimpleError(function (e) …
29. | local h(simpleError(msg, call))
30. | cli:::throw_error(err, parent = e)

Activity

  1. jennybc commented on Aug 28, 2025

    @jennybc
    Member

    Yes, I think this is the same thing as #317, which is now fixed in gargle (r-lib/gargle#293). I am about to do a gargle release (I have to, due to a deadline from CRAN), so this will be resolved very soon.

  2. jennybc commented on Aug 28, 2025

    @jennybc
    Member

    Weeelllll, I think your problem is slightly different, but I am hopeful that the fix I've made in gargle applies to you too. What we are seeing is an unexpected error while trying to report a problem gracefully. So I can't necessary eliminate that problem, but the gargle fix should surface it to you in the intended way.

  3. jennybc commented on Aug 28, 2025

    @jennybc
    Member

    Can I see your actual code? I'm interested in localfunctions.r and update_dibels_students().

  4. jennybc commented on Aug 30, 2025

    @jennybc
    Member

    I just experienced this myself! And it requires a new fix in gargle, which is in progress.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions