Skip to content

Commit 932e435

Browse files
committed
Cleanly distinguish Supervisor Cmd.Wait errors
The os.Process API is strange in that it returns an error instead of (ProcessState, error). This makes it difficult to distinguish between "regular" process errors and failures that occur while actually waiting on the process. Nevertheless, try to distinguish between these two cases to produce more accurate log messages: If the error is nil or unwraps into an *exec.ExitErr, treat it as a "regular" process error. Consider everything else an error indicating a problem with waiting. Signed-off-by: Tom Wieczorek <[email protected]>
1 parent 5ef4a6f commit 932e435

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

pkg/supervisor/supervisor.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,13 +86,19 @@ func (s *Supervisor) processWaitQuit(ctx context.Context, cmd *exec.Cmd) bool {
8686
}
8787
}
8888
case err := <-waitresult:
89-
if err != nil {
90-
s.log.WithError(err).Warn("Failed to wait for process")
91-
} else {
92-
s.log.Warnf("Process exited: %s", cmd.ProcessState)
89+
var exitErr *exec.ExitError
90+
state := cmd.ProcessState
91+
switch {
92+
case errors.As(err, &exitErr):
93+
state = exitErr.ProcessState
94+
fallthrough
95+
case err == nil:
96+
s.log.Error("Process terminated unexpectedly: ", state)
97+
default:
98+
s.log.WithError(err).Error("Failed to wait for process: ", state)
9399
}
100+
return false
94101
}
95-
return false
96102
}
97103

98104
// Supervise Starts supervising the given process

0 commit comments

Comments
 (0)