-
Notifications
You must be signed in to change notification settings - Fork 42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
roundup of cleanup fixes #144
Conversation
}() | ||
} | ||
} else { | ||
// not using this channel today | ||
close(errCh) | ||
} | ||
|
||
defer func() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We really shouldn't be catching panics this way. This only catches panics where the panic value is an error so it's kind of arbitrary anyways.
IIRC, this was added because we had a bunch of races around Close
and SetError
but those have since been fixed.
@@ -184,16 +184,14 @@ var RootCmd = &cmds.Command{ | |||
PostRun: cmds.PostRunMap{ | |||
cmds.CLI: func(res cmds.Response, re cmds.ResponseEmitter) error { | |||
clire := re.(cli.ResponseEmitter) | |||
|
|||
defer re.Close() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't need to do this explicitly anymore. It's up to the executor to close the response emitter.
return re.CloseWithError(nil) | ||
} | ||
|
||
func (re *responseEmitter) CloseWithError(err error) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO, it's easier to read this when all the close logic is in the same function.
Also fixes #113. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not fully familiar with this code, but this LGTM
* Don't catch panics. We mostly had this to catch issues with the _commands_ library but catching random panics is really not the best idea. Worse, this code was rather arbitrary and only caught panics implementing `error`. * Make sure to wait for the PostRun to finish before returning.
It wasn't a reliable way to determine if the command was "done". We need to wait for run, post-run, etc. to finish first. * Fixes #143 This commit: 1. Removes the exit channel from the CLI response emitter. 2. Adds a `Status()` function to the `cli.ResponseEmitter` as a replacement for (1). 3. Renames `Exit(code)` to `SetStatus(code)`. This new function doesn't immediately _do_ anything other than set the status. 4. Make sure to wait for _everything_ to finish before returning from `cli.Run`.
We inserted these while transitioning to the new API but we've never hit one.
This PR includes fixes/cleanups for a bunch of issues I noticed while debugging #143.
Checkout the commit messages for details. The important fix is waiting for the
Executor
to finish. before returning fromRun
. Not doing this was causing us to close the process beforeRun
was actually finished.