Skip to content

gcs_get_object creates file even when failed download #173

@muschellij2

Description

@muschellij2

If you pass in something to saveToDisk for gcs_get_object, it creates a file, even if the download fails.

##### MISSING CODE TO AUTHORIZE YOURSELF
library(googleCloudStorageR)
json_file = "my_nonexistent_file.json"
bucket = "str-bucket"
file.exists(json_file)
#> [1] FALSE
gcs_get_object(
  json_file,
  bucket = bucket,
  saveToDisk = json_file,
  overwrite = TRUE)
#> ℹ Downloading my_nonexistent_file.json
#> ℹ 2023-06-20 16:05:07 > Request Status Code:  403
#> ℹ Downloading my_nonexistent_file.json
#> Error in `abort_http()`:
#> ! http_403 Unspecified error
#> Backtrace:
#>     ▆
#>  1. └─googleCloudStorageR::gcs_get_object(...)
#>  2.   └─googleAuthR (local) ob()
#>  3.     └─googleAuthR:::doHttrRequest(...)
#>  4.       └─googleAuthR:::retryRequest(...)
#>  5.         └─googleAuthR:::abort_http(status_code, error)
#>  6.           └─rlang::abort(...)
#> ✖ Downloading my_nonexistent_file.json ... failed
readLines(json_file)
#> Warning in readLines(json_file): incomplete final line found on
#> 'my_nonexistent_file.json'
#> [1] "[email protected] does not have storage.objects.get access to the Google Cloud Storage object. Permission 'storage.objects.get' denied on resource (or it may not exist)."

Created on 2023-06-20 with reprex v2.0.2

Session info
sessioninfo::session_info()
#> ─ Session info ───────────────────────────────────────────────────────────────
#>  setting  value
#>  version  R version 4.2.2 (2022-10-31)
#>  os       Ubuntu 22.04.1 LTS
#>  system   x86_64, linux-gnu
#>  ui       X11
#>  language (EN)
#>  collate  en_US.UTF-8
#>  ctype    en_US.UTF-8
#>  tz       Etc/UTC
#>  date     2023-06-20
#>  pandoc   2.19.2 @ /usr/lib/rstudio-server/bin/quarto/bin/tools/ (via rmarkdown)
#> 
#> ─ Packages ───────────────────────────────────────────────────────────────────
#>  package             * version    date (UTC) lib source
#>  askpass               1.1        2019-01-13 [2] RSPM (R 4.2.0)
#>  assertthat            0.2.1      2019-03-21 [2] RSPM (R 4.2.0)
#>  cachem                1.0.8      2023-05-01 [1] RSPM (R 4.2.0)
#>  cli                   3.6.1      2023-03-23 [1] RSPM (R 4.2.0)
#>  curl                  5.0.1      2023-06-07 [1] RSPM (R 4.2.0)
#>  digest                0.6.31     2022-12-11 [1] RSPM (R 4.2.0)
#>  evaluate              0.21       2023-05-05 [1] RSPM (R 4.2.0)
#>  fansi                 1.0.4      2023-01-22 [1] RSPM (R 4.2.0)
#>  fastmap               1.1.1      2023-02-24 [1] RSPM (R 4.2.0)
#>  fs                    1.6.2      2023-04-25 [1] RSPM (R 4.2.0)
#>  gargle                1.5.0      2023-06-10 [1] RSPM (R 4.2.0)
#>  glue                  1.6.2      2022-02-24 [2] RSPM (R 4.2.0)
#>  googleAuthR           2.0.1      2023-04-11 [1] RSPM (R 4.2.0)
#>  googleCloudRunner     0.5.0.9000 2023-06-16 [1] Github (muschellij2/googleCloudRunner@0c1a0d3)
#>  googleCloudStorageR * 0.7.0      2021-12-16 [1] RSPM (R 4.2.0)
#>  googlePubsubR         0.0.4      2023-03-03 [1] RSPM (R 4.2.0)
#>  htmltools             0.5.5      2023-03-23 [1] RSPM (R 4.2.0)
#>  httr                  1.4.6      2023-05-08 [1] RSPM (R 4.2.0)
#>  jose                  1.2.0      2021-11-06 [1] RSPM (R 4.2.0)
#>  jsonlite              1.8.5      2023-06-05 [1] RSPM (R 4.2.0)
#>  knitr                 1.43       2023-05-25 [1] RSPM (R 4.2.0)
#>  lifecycle             1.0.3      2022-10-07 [2] RSPM (R 4.2.0)
#>  magrittr              2.0.3      2022-03-30 [2] RSPM (R 4.2.0)
#>  memoise               2.0.1      2021-11-26 [2] RSPM (R 4.2.0)
#>  metagce               0.4.0      2023-06-16 [1] Github (StreamlineDataScience/metagce@1196e43)
#>  openssl               2.0.6      2023-03-09 [1] RSPM (R 4.2.0)
#>  pillar                1.9.0      2023-03-22 [1] RSPM (R 4.2.0)
#>  R6                    2.5.1      2021-08-19 [2] RSPM (R 4.2.0)
#>  reprex                2.0.2      2022-08-17 [2] RSPM (R 4.2.0)
#>  rlang                 1.1.1      2023-04-28 [1] RSPM (R 4.2.0)
#>  rmarkdown             2.22       2023-06-01 [1] RSPM (R 4.2.0)
#>  rstudioapi            0.14       2022-08-22 [2] RSPM (R 4.2.0)
#>  sessioninfo           1.2.2.9000 2023-06-16 [1] Github (r-lib/sessioninfo@ec1ebd1)
#>  trailrun              0.5.4      2023-06-16 [1] Github (StreamlineDataScience/trailrun@3fa1010)
#>  utf8                  1.2.3      2023-01-31 [1] RSPM (R 4.2.0)
#>  vctrs                 0.6.2      2023-04-19 [1] RSPM (R 4.2.0)
#>  withr                 2.5.0      2022-03-03 [2] RSPM (R 4.2.0)
#>  xfun                  0.39       2023-04-20 [1] RSPM (R 4.2.0)
#>  yaml                  2.3.7      2023-01-23 [1] RSPM (R 4.2.0)
#>  zip                   2.3.0      2023-04-17 [1] RSPM (R 4.2.0)
#> 
#>  [1] /home/gcer/R
#>  [2] /usr/local/lib/R/site-library
#>  [3] /usr/local/lib/R/library
#> 
#> ──────────────────────────────────────────────────────────────────────────────

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