tidyverse/googlesheets4

misleading error if non-existent path used for gs4_auth()

nick-youngblut opened this issue · 2 comments

Command:

googlesheets4::gs4_auth(path="non-existent_path.json")

Output:

Error in `googlesheets4::gs4_auth()`:
! `path` does not represent a service account.
Did you provide the JSON for an OAuth client instead of for a service account?
Use `gs4_auth_configure()` to configure the OAuth client.
Run `rlang::last_trace()` to see where the error occurred.

It would help to have a check for whether the json file exists, and if not, provide an error stating that the provided path is incorrect.

sessionInfo

R version 4.3.1 (2023-06-16)
Platform: aarch64-apple-darwin20 (64-bit)
Running under: macOS Ventura 13.3

Matrix products: default
BLAS:   /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib 
LAPACK: /Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/lib/libRlapack.dylib;  LAPACK version 3.11.0

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

time zone: America/Los_Angeles
tzcode source: internal

attached base packages:
[1] stats     graphics  grDevices datasets  utils     methods   base     

other attached packages:
[1] googlesheets4_1.1.1 shinyBS_0.61.1      shiny_1.7.5        

loaded via a namespace (and not attached):
 [1] jsonlite_1.8.7    compiler_4.3.1    renv_1.0.2        promises_1.2.1    Rcpp_1.0.11       later_1.3.1      
 [7] fastmap_1.1.1     mime_0.12         R6_2.5.1          curl_5.1.0        tibble_3.2.1      openssl_2.1.1    
[13] pillar_1.9.0      rlang_1.1.1       utf8_1.2.3        httpuv_1.6.11     fs_1.6.3          cli_3.6.1        
[19] magrittr_2.0.3    digest_0.6.33     xtable_1.8-4      askpass_1.2.0     rappdirs_0.3.3    lifecycle_1.0.3  
[25] vctrs_0.6.3       gargle_1.5.2      glue_1.6.2        cellranger_1.1.0  googledrive_2.1.1 fansi_1.0.5      
[31] purrr_1.0.2       httr_1.4.7        tools_4.3.1       pkgconfig_2.0.3   ellipsis_0.3.2    htmltools_0.5.6.1

It's basically impossible to do much better than this, because path is actually passed through to jsonlite::fromJSON() and, yeah, it's often a filepath, but is could be "a JSON string, URL or file". See the docs for gs4_auth():

https://googlesheets4.tidyverse.org/reference/gs4_auth.html#arguments

gargle (and therefore packages like googlesheets4) actually use this functionality, i.e. the possibility of providing a JSON string. So, I can tell if the attempt to use path failed, but I can't tell if the user meant to provide a filepath or a JSON string.

I'm sort of assuming/hoping that the fact you saw this message at all did help you diagnose and fix your problem. In the past, we didn't even have this!

Upon further though, maybe I can improve on this message. I'll open an issue about it in gargle (which is where the error comes from).