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
10
cmd/cmd.go
10
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++ {
|
for try := 1; try <= *retries; try++ {
|
||||||
err = f()
|
err = f()
|
||||||
fs.CountError(err)
|
fs.CountError(err)
|
||||||
|
lastErr := accounting.Stats.GetLastError()
|
||||||
|
if err == nil {
|
||||||
|
err = lastErr
|
||||||
|
}
|
||||||
if !Retry || !accounting.Stats.Errored() {
|
if !Retry || !accounting.Stats.Errored() {
|
||||||
if try > 1 {
|
if try > 1 {
|
||||||
fs.Errorf(nil, "Attempt %d/%d succeeded", try, *retries)
|
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)
|
time.Sleep(d)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
lastErr := accounting.Stats.GetLastError()
|
|
||||||
if lastErr != nil {
|
if lastErr != nil {
|
||||||
fs.Errorf(nil, "Attempt %d/%d failed with %d errors and: %v", try, *retries, accounting.Stats.GetErrors(), lastErr)
|
fs.Errorf(nil, "Attempt %d/%d failed with %d errors and: %v", try, *retries, accounting.Stats.GetErrors(), lastErr)
|
||||||
} else {
|
} else {
|
||||||
|
@ -267,7 +270,12 @@ func Run(Retry bool, showStats bool, cmd *cobra.Command, f func() error) {
|
||||||
}
|
}
|
||||||
stopStats()
|
stopStats()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
nerrs := accounting.Stats.GetErrors()
|
||||||
|
if nerrs <= 1 {
|
||||||
log.Printf("Failed to %s: %v", cmd.Name(), err)
|
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)
|
resolveExitCode(err)
|
||||||
}
|
}
|
||||||
if showStats && (accounting.Stats.Errored() || *statsInterval > 0) {
|
if showStats && (accounting.Stats.Errored() || *statsInterval > 0) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue