Skip to content

Commit 509dcce

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 867e3e4 commit 509dcce

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
@@ -88,13 +88,19 @@ func (s *Supervisor) processWaitQuit(ctx context.Context, cmd *exec.Cmd) bool {
8888
}
8989
}
9090
case err := <-waitresult:
91-
if err != nil {
92-
s.log.WithError(err).Warn("Failed to wait for process")
93-
} else {
94-
s.log.Warnf("Process exited: ", cmd.ProcessState)
91+
var exitErr *exec.ExitError
92+
state := cmd.ProcessState
93+
switch {
94+
case errors.As(err, &exitErr):
95+
state = exitErr.ProcessState
96+
fallthrough
97+
case err == nil:
98+
s.log.Error("Process terminated unexpectedly: ", state)
99+
default:
100+
s.log.WithError(err).Error("Failed to wait for process: ", state)
95101
}
102+
return false
96103
}
97-
return false
98104
}
99105

100106
// Supervise Starts supervising the given process

0 commit comments

Comments
 (0)