ssh icon indicating copy to clipboard operation
ssh copied to clipboard

Error rather than warning if download fails

Open richfitz opened this issue 7 years ago • 4 comments

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)?

richfitz avatar May 03 '18 13:05 richfitz

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?

jeroen avatar May 27 '18 12:05 jeroen

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.

richfitz avatar May 29 '18 07:05 richfitz

What about

options(warn=2)

jxu avatar Jun 28 '19 23:06 jxu

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.')
}

yaotianran avatar Jul 26 '21 09:07 yaotianran