From 870b15313ec24318f76517f1eece89567eae5c18 Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Sun, 12 May 2019 18:39:29 +0100 Subject: [PATCH] cmd: log an ERROR for all commands which exit with non-zero status Before this change, rclone didn't report errors for commands which didn't return an error directly. For example `rclone ls` could encounter an error and rclone would log nothing, even though the exit code was non zero. After this change we always log a message if we are exiting with a non-zero exit code. --- cmd/cmd.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/cmd/cmd.go b/cmd/cmd.go index b8a8e6f62..439c68ef3 100644 --- a/cmd/cmd.go +++ b/cmd/cmd.go @@ -231,6 +231,10 @@ func Run(Retry bool, showStats bool, cmd *cobra.Command, f func() error) { for try := 1; try <= *retries; try++ { err = f() fs.CountError(err) + lastErr := accounting.Stats.GetLastError() + if err == nil { + err = lastErr + } if !Retry || !accounting.Stats.Errored() { if try > 1 { fs.Errorf(nil, "Attempt %d/%d succeeded", try, *retries) @@ -252,7 +256,6 @@ func Run(Retry bool, showStats bool, cmd *cobra.Command, f func() error) { time.Sleep(d) } } - lastErr := accounting.Stats.GetLastError() if lastErr != nil { fs.Errorf(nil, "Attempt %d/%d failed with %d errors and: %v", try, *retries, accounting.Stats.GetErrors(), lastErr) } else { @@ -267,7 +270,12 @@ func Run(Retry bool, showStats bool, cmd *cobra.Command, f func() error) { } stopStats() if err != nil { - log.Printf("Failed to %s: %v", cmd.Name(), err) + nerrs := accounting.Stats.GetErrors() + if nerrs <= 1 { + log.Printf("Failed to %s: %v", cmd.Name(), err) + } else { + log.Printf("Failed to %s with %d errors: last error was: %v", cmd.Name(), nerrs, err) + } resolveExitCode(err) } if showStats && (accounting.Stats.Errored() || *statsInterval > 0) {