Skip to content
This repository was archived by the owner on Apr 12, 2019. It is now read-only.

Commit 199484c

Browse files
author
Mura Li
committed
Rectify error handling
1 parent d5e562c commit 199484c

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

command.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,11 @@ func (c *Command) RunInDirTimeoutPipeline(timeout time.Duration, dir string, std
7070
return err
7171
}
7272

73-
return cmd.Wait()
73+
if err := cmd.Wait(); err == nil {
74+
return nil
75+
}
76+
77+
return ctx.Err()
7478
}
7579

7680
// RunInDirTimeout executes the command in given directory with given timeout,

command_test.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
package git
88

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

0 commit comments

Comments
 (0)