ipeaGIT / geobr

Easy access to official spatial data sets of Brazil in R and Python
https://ipeagit.github.io/geobr/
789 stars 118 forks source link

Error in read_* functions after timeout #259

Closed dhersz closed 2 years ago

dhersz commented 2 years ago
city_shape <- geobr::read_municipality(city_code)
#> Timeout was reached: [www.ipea.gov.br] Connection timed out after 10000 milliseconds
#> Problem connecting to data server. Please try geobr again in a few minutes.
#> Error in curl::curl_fetch_disk(url, x$path, handle = handle) : 
#>   Timeout was reached: [www.ipea.gov.br] Operation timed out after 10000 milliseconds with 0 out of 0 bytes received
city_shape <- geobr::read_municipality(city_code)
#> Error in read.table(file = file, header = header, sep = sep, quote = quote,  : 
#>   no lines available in input
geobr::read_amazon()
#> Error in read.table(file = file, header = header, sep = sep, quote = quote,  : 
#>   no lines available in input

Probably related to the metadata file.

rafapereirabr commented 2 years ago

Hi Daniel.

This problem can occur because of latency issue in our server where we store the data. When this problem occurs, geobr downloads and stores in memory a corrupted metadata file, so next read_ calls cannot find the data in the metadata.

short term solution In this case, the short term solution is to simply restart the R session or clean the temporary files.

long term solution The geobr package currently checks if there is internet connection on both sides (user and server), but I haven't found a way to test if there are latency issue. The long term solution here would be to (1) test connection latency, and (2) throw a message (and not an ERROR) where there is Connection timed out

dhersz commented 2 years ago

My problem with this error is that it's not clear in what is the problem.

Perhaps when reading the metadata file you could use tryCatch() to check for any errors (or more specifically, this error). In case of error you delete the metadata file and proceed with the usual process (download metadata file to later download the dataset). If the server is still unstable, you'll get the previous (and clearer) error message, regarding timeout.

rafapereirabr commented 2 years ago

oh well, I just got a message from CRAN saying that geobr is not "falling gracefully" . This needs to be fixed before Jan 8th

rafapereirabr commented 2 years ago

related SO question with promising solution. https://stackoverflow.com/questions/12193779/how-to-write-trycatch-in-r

rafapereirabr commented 2 years ago

I have wrapped all httr::GET(..) calls to download files with try( ..., silent = TRUE)