ropensci / vcr

Record and replay HTTP requests
https://docs.ropensci.org/vcr
Other
77 stars 12 forks source link

Slashes in cassette name causes cryptic error #159

Closed amoeba closed 4 years ago

amoeba commented 4 years ago

Bit of an edge case here but I thought I'd report. If I use a cassette name like "foo/bar" I get a cryptic error.

Steps to reproduce:

  1. Wrap a chunk of code that hits the network in a use_cassette block, specifying a cassette name with a forward slash in it. e.g., "foo/bar"
  2. Run devtools::test() so the test runs
  3. Observe the below error

Example:

In my test:

vcr::use_cassette("queue/x", {
  props <- rt_queue_properties("General")
})

Truncated devtools::test() output:

test_rt_queue_properties.R:4: warning: we can get the properties of a queue
cannot open file './queue/x.yml': No such file or directory

To get the error to go away, I removed the forward slash.

Session Info ```r > devtools::session_info() ─ Session info ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── setting value version R version 3.6.2 (2019-12-12) os macOS Catalina 10.15.3 system x86_64, darwin15.6.0 ui RStudio language (EN) collate en_US.UTF-8 ctype en_US.UTF-8 tz America/Juneau date 2020-02-26 ─ Packages ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── package * version date lib source assertthat 0.2.1 2019-03-21 [1] CRAN (R 3.6.0) backports 1.1.5 2019-10-02 [1] CRAN (R 3.6.0) base64enc 0.1-3 2015-07-28 [1] CRAN (R 3.6.0) callr 3.4.2 2020-02-12 [1] CRAN (R 3.6.0) cli 2.0.1 2020-01-08 [1] CRAN (R 3.6.0) colorspace 1.4-1 2019-03-18 [1] CRAN (R 3.6.0) crayon 1.3.4 2017-09-16 [1] CRAN (R 3.6.0) crul 0.9.0 2019-11-06 [1] CRAN (R 3.6.0) curl 4.3 2019-12-02 [1] CRAN (R 3.6.0) desc 1.2.0 2018-05-01 [1] CRAN (R 3.6.0) devtools 2.2.1 2019-09-24 [1] CRAN (R 3.6.0) digest 0.6.24 2020-02-12 [1] CRAN (R 3.6.0) ellipsis 0.3.0 2019-09-20 [1] CRAN (R 3.6.0) evaluate 0.14 2019-05-28 [1] CRAN (R 3.6.0) fansi 0.4.1 2020-01-08 [1] CRAN (R 3.6.0) fs 1.3.1 2019-05-06 [1] CRAN (R 3.6.0) glue 1.3.1 2019-03-12 [1] CRAN (R 3.6.0) hms 0.5.3 2020-01-08 [1] CRAN (R 3.6.0) htmltools 0.4.0 2019-10-04 [1] CRAN (R 3.6.0) httpcode 0.2.0 2016-11-14 [1] CRAN (R 3.6.0) httr 1.4.1 2019-08-05 [1] CRAN (R 3.6.0) jsonlite 1.6.1 2020-02-02 [1] CRAN (R 3.6.0) kableExtra * 1.1.0 2019-03-16 [1] CRAN (R 3.6.0) knitr * 1.28 2020-02-06 [1] CRAN (R 3.6.2) lazyeval 0.2.2 2019-03-15 [1] CRAN (R 3.6.0) lifecycle 0.1.0 2019-08-01 [1] CRAN (R 3.6.0) magrittr 1.5 2014-11-22 [1] CRAN (R 3.6.0) memoise 1.1.0 2017-04-21 [1] CRAN (R 3.6.0) munsell 0.5.0 2018-06-12 [1] CRAN (R 3.6.0) pillar 1.4.3 2019-12-20 [1] CRAN (R 3.6.0) pkgbuild 1.0.6 2019-10-09 [1] CRAN (R 3.6.0) pkgconfig 2.0.3 2019-09-22 [1] CRAN (R 3.6.0) pkgload 1.0.2 2018-10-29 [1] CRAN (R 3.6.0) prettyunits 1.1.1 2020-01-24 [1] CRAN (R 3.6.0) processx 3.4.2 2020-02-09 [1] CRAN (R 3.6.0) ps 1.3.2 2020-02-13 [1] CRAN (R 3.6.0) R6 2.4.1 2019-11-12 [1] CRAN (R 3.6.0) Rcpp 1.0.3 2019-11-08 [1] CRAN (R 3.6.0) readr 1.3.1 2018-12-21 [1] CRAN (R 3.6.0) remotes 2.1.0 2019-06-24 [1] CRAN (R 3.6.0) rlang 0.4.4 2020-01-28 [1] CRAN (R 3.6.2) rmarkdown 2.1 2020-01-20 [1] CRAN (R 3.6.0) rprojroot 1.3-2 2018-01-03 [1] CRAN (R 3.6.0) rstudioapi 0.11 2020-02-07 [1] CRAN (R 3.6.0) rt * 0.1.0 2020-02-26 [1] local rvest 0.3.5 2019-11-08 [1] CRAN (R 3.6.0) scales 1.1.0 2019-11-18 [1] CRAN (R 3.6.0) sessioninfo 1.1.1 2018-11-05 [1] CRAN (R 3.6.0) stringi 1.4.6 2020-02-17 [1] CRAN (R 3.6.2) stringr 1.4.0 2019-02-10 [1] CRAN (R 3.6.0) testthat 2.3.1 2019-12-01 [1] CRAN (R 3.6.0) tibble 2.1.3 2019-06-06 [1] CRAN (R 3.6.0) triebeard 0.3.0 2016-08-04 [1] CRAN (R 3.6.0) urltools 1.7.3 2019-04-14 [1] CRAN (R 3.6.0) usethis 1.5.1 2019-07-04 [1] CRAN (R 3.6.0) utf8 1.1.4 2018-05-24 [1] CRAN (R 3.6.0) vcr * 0.4.0 2019-12-07 [1] CRAN (R 3.6.0) vctrs 0.2.2 2020-01-24 [1] CRAN (R 3.6.0) viridisLite 0.3.0 2018-02-01 [1] CRAN (R 3.6.0) webshot 0.5.2 2019-11-22 [1] CRAN (R 3.6.0) withr 2.1.2 2018-03-15 [1] CRAN (R 3.6.0) xfun 0.12 2020-01-13 [1] CRAN (R 3.6.0) xml2 1.2.2.9000 2020-02-02 [1] local yaml 2.2.1 2020-02-01 [1] CRAN (R 3.6.0) [1] /Library/Frameworks/R.framework/Versions/3.6/Resources/library ```
sckott commented 4 years ago

thanks, we've been dealing with trying to handle invalid cassette names (#116) - looks like another case we need to handle, will have a look

sckott commented 4 years ago

@amoeba was the idea to have the cassette name by x within a queue directory? Or to be queue/x?

sckott commented 4 years ago

I think we should not allow slashes, so I've added those to disallowed characters in cassette names. If you get the dev version use_cassette will check for disallowed cassette name characters, and you can add a helper fxn check_cassette_names() to the helper-pkgname.R file in your pkg which will check only for duplicated cassette names

amoeba commented 4 years ago

The idea was just to match the cassette name to the testthat context I was using. So there's no need for me to have the slashes and, as a user, I'd be totally fine having them escaped or get an error if I try to use them. Thanks!

aaronwolen commented 4 years ago

Might be worth looking at fs::path_file_sanitize(), which includes a comprehensive list of illegal characters that should be removed from file names.

sckott commented 4 years ago

thanks @aaronwolen - will do

amoeba commented 4 years ago

Thanks @sckott and @aaronwolen !