chore: better errors

Signed-off-by: Armando Ruocco <armando.ruocco@enterprisedb.com>
This commit is contained in:
Armando Ruocco 2024-11-28 17:25:22 +01:00 committed by Francesco Canovai
parent 1849a98817
commit 89e486cce0

View File

@ -34,7 +34,7 @@ func unixHealthCheck() *cobra.Command {
dialPath := fmt.Sprintf("unix://%s", path.Join("/plugins", metadata.PluginName)) dialPath := fmt.Sprintf("unix://%s", path.Join("/plugins", metadata.PluginName))
cli, cliErr := grpc.NewClient(dialPath, grpc.WithTransportCredentials(insecure.NewCredentials())) cli, cliErr := grpc.NewClient(dialPath, grpc.WithTransportCredentials(insecure.NewCredentials()))
if cliErr != nil { if cliErr != nil {
log.Error(cliErr, "error while building client") log.Error(cliErr, "while building the client")
return cliErr return cliErr
} }
@ -44,18 +44,25 @@ func unixHealthCheck() *cobra.Command {
&grpc_health_v1.HealthCheckRequest{}, &grpc_health_v1.HealthCheckRequest{},
) )
if healthErr != nil { if healthErr != nil {
log.Error(healthErr, "healthcheck call failed") log.Error(healthErr, "while executing the healthcheck call")
return healthErr return healthErr
} }
log.Info("received status: %s", res.Status.String()) if res.Status == grpc_health_v1.HealthCheckResponse_SERVING {
switch res.Status { log.Trace("healthcheck response OK")
case grpc_health_v1.HealthCheckResponse_SERVING:
os.Exit(0) os.Exit(0)
return nil
}
log.Error(fmt.Errorf("unexpected healthcheck response: %v", res.Status),
"while processing healthcheck response")
// exit code 1 is returned when we exit from the function with an error
switch res.Status {
case grpc_health_v1.HealthCheckResponse_UNKNOWN: case grpc_health_v1.HealthCheckResponse_UNKNOWN:
os.Exit(1)
case grpc_health_v1.HealthCheckResponse_NOT_SERVING:
os.Exit(2) os.Exit(2)
case grpc_health_v1.HealthCheckResponse_NOT_SERVING:
os.Exit(3)
default: default:
os.Exit(125) os.Exit(125)
} }