* Rectify error handling

* Log the error returned by exec.Wait
This commit is contained in:
Mura Li 2017-05-26 13:11:55 +08:00 коммит произвёл Lunny Xiao
Родитель f0a094c4f9
Коммит 4c374b37db
2 изменённых файлов: 7 добавлений и 5 удалений

Просмотреть файл

@ -70,7 +70,11 @@ func (c *Command) RunInDirTimeoutPipeline(timeout time.Duration, dir string, std
return err
}
return cmd.Wait()
if err := cmd.Wait(); err != nil {
log("exec.Wait: %v", err)
}
return ctx.Err()
}
// RunInDirTimeout executes the command in given directory with given timeout,

Просмотреть файл

@ -7,6 +7,7 @@
package git
import (
"context"
"testing"
"time"
)
@ -32,10 +33,7 @@ func TestRunInDirTimeoutPipelineAlwaysTimeout(t *testing.T) {
cmd := NewCommand("hash-object --stdin")
for i := 0; i < maxLoops; i++ {
if err := cmd.RunInDirTimeoutPipeline(1*time.Microsecond, "", nil, nil); err != nil {
// 'context deadline exceeded' when the error is returned by exec.Start
// 'signal: killed' when the error is returned by exec.Wait
// It depends on the point of the time (before or after exec.Start returns) at which the timeout is triggered.
if err.Error() != "context deadline exceeded" && err.Error() != "signal: killed" {
if err != context.DeadlineExceeded {
t.Fatalf("Testing %d/%d: %v", i, maxLoops, err)
}
}