rstudio / pins-r

Pin, discover, and share resources
https://pins.rstudio.com
Other
312 stars 63 forks source link

`board_register()` fails with error "argument is of length zero" #529

Closed tllove24 closed 2 years ago

tllove24 commented 2 years ago

Hi! I'm using the board_rsconnect to pin files to RSConnect in R version 3.5. Since this week, I'm seeing this error when calling board_rsconnect. Wondering if there's anything changed. Thanks!

Error in if (!is.na(cache)) { : argument is of length zero      
{bash_operator.py:126} INFO - Calls: board_register -> fun -> board_rsconnect -> new_board 
andrie commented 2 years ago

Can you please provide more detail about exactly what you are trying to do and what happens, including your environment?

A good error report will include:

For example, here is an error report that I filed internally about pins earlier this week:

The code:

library(pins)
board <- board_rsconnect(
  server = "https://connect.rstudioservices.com",
  key = Sys.getenv("RSTUDIOSERVICES_CONNECT_API_KEY")

)
board %>% 
  pin_read("andrie/white_glove_calendar_data")

The error message:

Error: [ENOENT] Failed to search directory '/mnt/home/andrie/.cache/pins/rsc-e62371cfd77db754024f9c5ed3556a73/b57621bc-fd09-4a42-8a0e-e8d7030d11c1': no such file or directory

The result of traceback():

15: (function (..., call. = TRUE, domain = NULL) 
    {
        if (...length() == 1L && inherits(..1, "condition")) {
            cond <- ..1
            if (nargs() > 1L) 
                warning("additional arguments ignored in stop()")
            message <- conditionMessage(cond)
            call <- conditionCall(cond)
            .Internal(.signalCondition(cond, message, call))
            .Internal(.dfltStop(message, call))
        }
        else .Internal(stop(call., .makeMessage(..., domain = domain)))
    })(structure(list(message = "[ENOENT] Failed to search directory '/mnt/home/andrie/.cache/pins/rsc-e62371cfd77db754024f9c5ed3556a73/b57621bc-fd09-4a42-8a0e-e8d7030d11c1': no such file or directory"), class = c("ENOENT", 
    "fs_error", "error", "condition"), location = "dir.cc:89"))
14: dir_map(old, identity, all, recurse, type, fail)
13: fs::dir_ls(fs::path(board$cache, guid))
12: rsc_content_version_cached(board, guid)
11: value[[3L]](cond)
10: tryCatchOne(expr, names, parentenv, handlers[[1L]])
9: tryCatchList(expr, classes, parentenv, handlers)
8: tryCatch(rsc_content_version_live(board, guid), error = function(cnd) {
       rsc_content_version_cached(board, guid)
   })
7: rsc_content_version(board, content$guid)
6: pin_meta.pins_board_rsconnect(board, name, version = version)
5: pin_meta(board, name, version = version)
4: pin_fetch.pins_board_rsconnect(board, name, version = version, 
       ...)
3: pin_fetch(board, name, version = version, ...)
2: pin_read(., "andrie/white_glove_calendar_data")
1: board %>% pin_read("andrie/white_glove_calendar_data")

And then provide your sessionInfo()

The more information you provide, the easier it will be for us to help you.

tllove24 commented 2 years ago

Thanks Andrie for you quick response! Please see details below, I think it is because of the 3.5.0 env, I tested in 3.6, it worked.

The code:

library(pins)
rsc_key = Sys.getenv("RSCONNECT_KEY")
board_register("rsconnect", server = "https://rstudiocondev.xxxx.com", 
               key = rsc_key )

The error message:

Error in if (!is.na(cache)) { : argument is of length zero
Calls: board_register -> fun -> board_rsconnect -> new_board

trackback()

4: new_board("pins_board_rsconnect", api = c(0, 1), name = name, 
       cache = cache, url = server$url, account = server$account, 
       server_name = server$server_name, auth = server$auth, versioned = versioned, 
       use_cache_on_failure = use_cache_on_failure)
3: board_rsconnect(name = name, server = server, account = account, 
       key = key, output_files = output_files, cache = cache, ...)
2: fun(name = name %||% board, cache = cache, versions = versions, 
       ...)
1: board_register("rsconnect", server = "https://rstudiocondev.xxxx.com", 
       key = rsc_key )

sessionInfo() compiler_3.5.0

andrie commented 2 years ago

Can you please check the sessionInfo()? I would normally expect to see your OS version, your R version, but also the version of pins and other packages that you have loaded.

tllove24 commented 2 years ago

You are right, apologies for the confusion.

R version 3.5.0 (2018-04-23)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Red Hat Enterprise Linux

Matrix products: default
BLAS: /opt/microsoft/ropen/3.5.0/lib64/R/lib/libRblas.so
LAPACK: /opt/microsoft/ropen/3.5.0/lib64/R/lib/libRlapack.so

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C               LC_TIME=en_US.UTF-8       
 [4] LC_COLLATE=en_US.UTF-8     LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                  LC_ADDRESS=C              
[10] LC_TELEPHONE=C             LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

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

other attached packages:
[1] filelock_1.0.2 rappdirs_0.3.3 dplyr_1.0.7    pins_1.0.0    

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.1                    rstudioapi_0.13               magrittr_2.0.1               
 [4] hms_1.1.0                     odbc_1.3.2                    tidyselect_1.1.1             
 [7] bit_4.0.4                     R6_2.4.0                      rlang_0.4.11                 
[10] fansi_0.4.2                   httr_1.4.2                    
[13] blob_1.2.1                    tools_3.5.0                   utf8_1.2.1                   
[16] DBI_1.1.1                     remotes_2.3.0                 ellipsis_0.3.2               
[19] bit64_4.0.5                   assertthat_0.2.1              tibble_3.1.2                 
[22] lifecycle_1.0.0               crayon_1.4.1                  purrr_0.3.4                  
[25] fs_1.5.0                      vctrs_0.3.8                   glue_1.4.2                   
[28] compiler_3.5.0                pillar_1.6.1                  generics_0.1.0               
[31] pkgconfig_2.0.3 
andrie commented 2 years ago

I think you should try one of two things:

With the legacy API, use board_register_rsconnect() directly:

library(pins)
rsc_key = Sys.getenv("RSCONNECT_KEY")
board_register_rsconnect( server = "https://rstudiocondev.xxxx.com", 
               key = rsc_key )

But it's probably a good time to switch to the new API:

library(pins)
board <- board_rsconnect(
  server = "https://rstudiocondev.xxxx.com",
  key = Sys.getenv("RSCONNECT_KEY")

)
board %>% 
  pin_write(...)
tllove24 commented 2 years ago

Thanks! the connection worked, however the pin_write failed this time:

Code:

board <- board_rsconnect("rsconnect", server = "rstudiocondev.xxxx.com", 
                                       key = "key")

board %>% pin_write(a, 
    name = "a", 
    description = "a",
    board = "rsconnect")

Error:

Error: `board` must be a pin board

traceback:

6: stop(fallback)
5: signal_abort(cnd)
4: abort("`board` must be a pin board")
3: check_board(board, "pin_write()", "pin()")
2: pin_write(., a, name = "a", 
       description = "a", board = "rsconnect")
1: board %>% pin_write(a, name = "a", 
       description = "a", board = "rsconnect")

however, board seems to be a pin board board

Pin board <pins_board_rsconnect>
Cache size: 0
Pins [24]:  '...'
andrie commented 2 years ago

Yes, that's because you've inserted an argument into the code that breaks the board_rsconnect() API.

Try:

board <- board_rsconnect(server = "rstudiocondev.xxxx.com", 
                                       key = "key")

board %>% pin_write(a, 
    name = "a", 
    description = "a"
)
tllove24 commented 2 years ago

Thanks Andrie! I got a new error, I think this is something from my side, but just want to confirm before I talk to someone else. Thank you so much for your help!

board %>% pin_write(a, 
     name = "a", 
     description = "a")
Guessing `type = 'rds'`
Error in rsc_check_status(req) : Not Found (HTTP 404).
> traceback()
13: stop(http_condition(x, "error", task = task, call = call))
12: httr::stop_for_status(req)
11: rsc_check_status(req)
10: rsc_GET(board, "v1/content", list(name = name$name))
9: rsc_content_find(board, name, warn = FALSE)
8: doTryCatch(return(expr), name, parentenv, handler)
7: tryCatchOne(expr, names, parentenv, handlers[[1L]])
6: tryCatchList(expr, classes, parentenv, handlers)
5: tryCatch({
       guid <- rsc_content_find(board, name, warn = FALSE)$guid
       rsc_content_update(board, guid, metadata, access_type = access_type)
       guid
   }, pins_pin_missing = function(e) {
       rsc_content_create(board, name, metadata, access_type = access_type)$guid
   })
4: pin_store.pins_board_rsconnect(board, name, path, meta, versioned = versioned, 
       x = x, ...)
3: pin_store(board, name, path, meta, versioned = versioned, x = x, 
       ...)
2: pin_write(., a, name = "a", description = "a")
1: board %>% pin_write(a, name = "a", description = "a")
Yogeshwara commented 2 years ago

Could you please post how you got the "Error in rsc_check_status(req) : Not Found (HTTP 404)." resolved?

tllove24 commented 2 years ago

Hi, I was not able to get the HTTP error resolved, instead, I installed an earlier version of the pins package.

andrie commented 2 years ago

Can you please open a support ticket so we can take a look? Please tell the support team to add me to the ticket.

hadley commented 2 years ago

I think we should re-open this issue.

sellorm commented 2 years ago

@Yogeshwara If you're seeing that error, it might be worth checking to see if you have anything like a reverse proxy or Web Application Firewall in front of Connect that may be causing an issue.

We saw something similar in #539, which turned out to be a WAF rule blocking certain types of API request.

MattNickodemus commented 2 years ago

I am having the same error when using board_rsconnect to pin files to RSConnect. We have opened a support ticket and asked for Andrie to be added.

Code

library(pins)

api_key <- keyring::key_get("pins", "api_key")

rsconnect_board <- board_rsconnect(key=api_key, server="https://my.server.com")

data <- iris

pin_name <- "reprex_pin"

rsconnect_board %>% pin_write(data, pin_name)

Error

Guessing `type = 'rds'`
Error in rsc_check_status(req) : Not Found (HTTP 404).

Traceback

13: stop(http_condition(x, "error", task = task, call = call))
12: httr::stop_for_status(req)
11: rsc_check_status(req)
10: rsc_GET(board, "v1/content", list(name = name$name))
9: rsc_content_find(board, name, warn = FALSE)
8: doTryCatch(return(expr), name, parentenv, handler)
7: tryCatchOne(expr, names, parentenv, handlers[[1L]])
6: tryCatchList(expr, classes, parentenv, handlers)
5: tryCatch({
       guid <- rsc_content_find(board, name, warn = FALSE)$guid
       rsc_content_update(board, guid, metadata, access_type = access_type)
       guid
   }, pins_pin_missing = function(e) {
       rsc_content_create(board, name, metadata, access_type = access_type)$guid
   })
4: pin_store.pins_board_rsconnect(board, name, path, meta, versioned = versioned, 
       x = x, ...)
3: pin_store(board, name, path, meta, versioned = versioned, x = x, 
       ...)
2: pin_write(., data, pin_name)
1: rsconnect_board %>% pin_write(data, pin_name)

Session Info

R version 4.1.2 (2021-11-01)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Big Sur 10.16

Matrix products: default
LAPACK: /Library/Frameworks/R.framework/Versions/4.1/Resources/lib/libRlapack.dylib

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

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

other attached packages:
[1] pins_1.0.0

loaded via a namespace (and not attached):
 [1] fansi_0.5.0      digest_0.6.28    crayon_1.4.2     utf8_1.2.2       withr_2.4.2     
 [6] assertthat_0.2.1 rappdirs_0.3.3   R6_2.5.1         lifecycle_1.0.1  jsonlite_1.7.2  
[11] magrittr_2.0.1   pillar_1.6.4     httr_1.4.2       rlang_0.4.12     curl_4.3.2      
[16] fs_1.5.0         vctrs_0.3.8      ellipsis_0.3.2   keyring_1.2.0    tools_4.1.2     
[21] glue_1.5.0       yaml_2.2.1       compiler_4.1.2   pkgconfig_2.0.3  tibble_3.1.6  
sellorm commented 2 years ago

@MattNickodemus it would be worth checking your Connect server environment for proxies and web application firewalls. We've had some reports of WAFs in particular blocking some of the Connect API calls that pins uses.

MattNickodemus commented 2 years ago

@sellorm Our IT team checked the Connect server environment and there are no issues with proxies or firewalls. We installed a previous version of the pins package and that resolved the issue. However, we would like to be able to run the latest version. @andrie, we still have an open ticket with @rstudio but they have asked that we resolve the issue here.

hadley commented 2 years ago

@MattNickodemus your problem doesn't appear to be related to this issue, so I'd recommend creating a new issue.

hadley commented 2 years ago

The root cause of the issue here is that board_register() defaults to name = NULL, which causes board_cache_path() to generate a length-0 character vector, which then cause is.na() to return a length-0 logical vector, which then causes if to error. I think the easiest fix is not to compute the cache in board_register() since the individual boards should all do it (and I'll fix if they don't).

github-actions[bot] commented 2 years ago

This issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with a reprex: https://reprex.tidyverse.org) and link to this issue.