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 all commits
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 {
log("exec.Wait: %v", err)
Copy link
Member

Choose a reason for hiding this comment

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

should it be log.Warn instead, and include more info about the command being run and the name of the function it's coming from ?

Copy link
Author

Choose a reason for hiding this comment

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

That would be a bit of more involved since there is an existing function called log within the package. I can give a nickname to the logger at the import statement but that looks weird and inconsistent with the rest of the package. The plan B is to rename the internal log function with another name, or to migrate all the uses of the log function with the logger's equivalent. But that would be beyond the scope of this PR.

Copy link
Member

Choose a reason for hiding this comment

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

Oops, sorry. I just realized this was the git module and not gitea itself.

}

return ctx.Err()
}

// 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