ropensci / ssh

Native SSH client in R based on libssh
https://docs.ropensci.org/ssh
Other
127 stars 21 forks source link

Error rather than warning if download fails #7

Open richfitz opened 6 years ago

richfitz commented 6 years ago

ssh::scp_download just warns if upload fails rather than errors - can this be turned into an error (even if it's an option that one has to set)?

jeroen commented 6 years ago

Yeah I'm not entirely sure yet how to deal with this. If you are downloading many files, and one fails, should the entire operation be aborted? What about files that you already downloaded?

richfitz commented 6 years ago

My thoughts:

I personally really dislike warnings in R - they're easily lost and don't get printed at a useful time. If it's informational and requires no user action I prefer message and if it's likely something terrible happened then I prefer errors (same idea as https://dave.cheney.net/2015/11/05/lets-talk-about-logging) but I recognise that's just a personal view.

How about return a logical vector TRUE/FALSE for success and include a must_work argument (so that if all files must be transferred successfully then it's easy to throw).

Because of the manipulation of global state you can't make the whole thing atomic (all work or none work) and scp itself doesn't try.

jxu commented 5 years ago

What about

options(warn=2)
yaotianran commented 3 years ago

With tryCatch one can easily capture errors or warnings

exception = tryCatch(
      {
       # something you want to do
      },
      error = function(e) e,
      warning = function(w) w
   )
if (inherits(exception, 'warning')) {
   stop('An error occured.')
}