forked from TrueCloudLab/rclone
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.
This commit is contained in:
parent
62a7e44e86
commit
870b15313e
1 changed files with 10 additions and 2 deletions
12
cmd/cmd.go
12
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) {
|
||||
|
|
Loading…
Reference in a new issue