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

Conversation

typeless
Copy link

@typeless typeless commented Apr 8, 2017

For #42 and #41

Sanitizing the error handling a little bit, now it looks nicer.

Copy link
Member

@strk strk left a comment

Choose a reason for hiding this comment

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

Please don't remove comments unless they are bogus, and maybe replace them with correct ones even in that case.

command.go Outdated
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.

// '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).

@@ -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.

@strk
Copy link
Member

strk commented Apr 8, 2017

LGTM

@ethantkoenig
Copy link
Member

LGTM

@lunny lunny merged commit 4c374b3 into go-gitea:master May 26, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants