fix: prevent panic on nil pointer in ServiceInfo method

Fixes #2138

`FilterMessages` might return `nil` resp if it extracts errors into
`err` from `resp`.

Signed-off-by: Andrey Smirnov <smirnov.andrey@gmail.com>
This commit is contained in:
Andrey Smirnov
2020-05-25 22:39:49 +03:00
committed by talos-bot
parent 87793d737c
commit 9ddbf95bb1

View File

@@ -592,13 +592,19 @@ func (c *Client) ServiceInfo(ctx context.Context, id string, callOptions ...grpc
)
if err != nil {
return
return services, err
}
var filtered interface{}
filtered, err = FilterMessages(resp, err)
resp, _ = filtered.(*machineapi.ServiceListResponse) //nolint: errcheck
// FilterMessages might remove responses if they actually contain errors,
// errors will be merged into `resp`.
if resp == nil {
return services, err
}
for _, resp := range resp.Messages {
for _, svc := range resp.Services {
if svc.Id == id {
@@ -610,7 +616,7 @@ func (c *Client) ServiceInfo(ctx context.Context, id string, callOptions ...grpc
}
}
return
return services, err
}
// ServiceStart starts a service.