ropensci / tidyhydat

An R package to import Water Survey of Canada hydrometric data and make it tidy
https://docs.ropensci.org/tidyhydat
Apache License 2.0
70 stars 19 forks source link

Attempting to load tidyhydat with no internet causes an error #149

Closed joethorley closed 3 years ago

joethorley commented 3 years ago

Attempting to load tidyhydat with no internet causes an error - is it possible to replace the error with a warning so that scripts that use tidyhydat can be run without an internet connection?

> library(tidyhydat)
● Checking for a new version of HYDAT...

Error: package or namespace load failed for ‘tidyhydat’:
 .onAttach failed in attachNamespace() for 'tidyhydat', details:
  call: NULL
  error: No access to internet
Backtrace:
    █
 1. └─base::library(tidyhydat)
 2.   └─base::tryCatch(...)
 3.     └─base:::tryCatchList(expr, classes, parentenv, handlers)
 4.       └─base:::tryCatchOne(expr, names, parentenv, handlers[[1L]])
 5.         └─value[[3L]](cond)
> 
boshek commented 3 years ago

👋 @joethorley

Yep that's a good call. Seems like I really just need to check sooner if the user has internet then I don't need the hard stop. Any thoughts on how to write a test that mimics no internet?

joethorley commented 3 years ago

@boshek - that's great. It's never anything I've done before.

This may be of interest

https://community.rstudio.com/t/unit-testing-for-non-working-internet-connection/31894

boshek commented 3 years ago

@joethorley are you able to check to see if the changes on the no-internet branch work for your purposes?

remotes::install_github("ropensci/tidyhydat")

Still trying to assess whether I actually need a test for this.

joethorley commented 3 years ago

That works for me - it doesn't issue a warning on load but in my opinion this is fine (even desirable) and then errors when attempting to download which is desirable with an informative error.

I'm not sure that a test is required.

> library(tidyhydat)
● Checking for a new version of HYDAT...

x Your version of HYDAT is out of date. Use download_hydat() to get the new version.

# switch off wifi

> library(tidyhydat)
> tidyhydat::download_hydat()
Downloading HYDAT will take ~10 minutes.
This will remove any older versions of HYDAT
Is that okay?
────────────────────────────────────────────────────────────────────────────────────────────

1: Yes
2: No

Selection: 1
● Downloading HYDAT.sqlite3 to ~/Library/Application Support/tidyhydat
Error in curl::curl_fetch_memory(url, handle = handle) : 
  Could not resolve host: collaboration.cmc.ec.gc.ca
Backtrace:
    █
 1. └─tidyhydat::download_hydat()
 2.   └─httr::GET(base_url)
 3.     └─httr:::request_perform(req, hu$handle$handle)
 4.       ├─[ httr:::request_fetch(...) ]
 5.       └─httr:::request_fetch.write_memory(req$output, req$url, handle)
 6.         └─curl::curl_fetch_memory(url, handle = handle)