Skip to content

Commit 5d0d64e

Browse files
committed
chore: better errors
Signed-off-by: Armando Ruocco <[email protected]>
1 parent 2bfbd4c commit 5d0d64e

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

internal/cmd/healthcheck/main.go

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func unixHealthCheck() *cobra.Command {
3434
dialPath := fmt.Sprintf("unix://%s", path.Join("/plugins", metadata.PluginName))
3535
cli, cliErr := grpc.NewClient(dialPath, grpc.WithTransportCredentials(insecure.NewCredentials()))
3636
if cliErr != nil {
37-
log.Error(cliErr, "error while building client")
37+
log.Error(cliErr, "while building the client")
3838
return cliErr
3939
}
4040

@@ -44,18 +44,25 @@ func unixHealthCheck() *cobra.Command {
4444
&grpc_health_v1.HealthCheckRequest{},
4545
)
4646
if healthErr != nil {
47-
log.Error(healthErr, "healthcheck call failed")
47+
log.Error(healthErr, "while executing the healthcheck call")
4848
return healthErr
4949
}
5050

51-
log.Info("received status: %s", res.Status.String())
52-
switch res.Status {
53-
case grpc_health_v1.HealthCheckResponse_SERVING:
51+
if res.Status == grpc_health_v1.HealthCheckResponse_SERVING {
52+
log.Trace("healthcheck response OK")
5453
os.Exit(0)
54+
return nil
55+
}
56+
57+
log.Error(fmt.Errorf("unexpected healthcheck response: %v", res.Status),
58+
"while processing healthcheck response")
59+
60+
// exit code 1 is returned when we exit from the function with an error
61+
switch res.Status {
5562
case grpc_health_v1.HealthCheckResponse_UNKNOWN:
56-
os.Exit(1)
57-
case grpc_health_v1.HealthCheckResponse_NOT_SERVING:
5863
os.Exit(2)
64+
case grpc_health_v1.HealthCheckResponse_NOT_SERVING:
65+
os.Exit(3)
5966
default:
6067
os.Exit(125)
6168
}

0 commit comments

Comments
 (0)