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

Rectify error handling #44

Merged
merged 2 commits into from
May 26, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion command.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
return nil
}

return ctx.Err()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And what happens to err ? Looks like simply getting lost ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about swapping the conditiona and returning err if not nil and return nil outside the condition block ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The err returned by exec.Wait is discarded in favor of ctx.Err(). Because exec.Wait() will returns a string 'signal: killed', which isn't good to depend on and is less meaningful. I don't have a good idea to encode the two errors (exec.Wait's and ctx.Err's) into one cleanly either.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe just log it ?

Copy link
Author

@typeless typeless Apr 8, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean logging the error of Wait and returning the error of ctx.Err() or something else?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes log the error of Wait

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

}

// RunInDirTimeout executes the command in given directory with given timeout,
Expand Down
6 changes: 2 additions & 4 deletions command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
package git

import (
"context"
"testing"
"time"
)
Expand All @@ -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 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you want to remove documentation in those comments ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since that is encapsulated into RunInDirTimeoutPipeline and the test won't be exposed to the nuances anymore (which is what I hope for).

t.Fatalf("Testing %d/%d: %v", i, maxLoops, err)
}
}
Expand Down