Skip to content
Snippets Groups Projects
Commit a92b4001 authored by Malte Bauch's avatar Malte Bauch
Browse files

Add error handling for methods of DeviceModelClient

A response of grpc calls within methods of DeviceModelClient is nil as
soon as an error occured within the call. In some methods values of the
response were directly accessed and returned. This can lead to a
segmentation fault if the response is nil.

Catching errors should prevent this.
parent b406addb
No related branches found
No related tags found
1 merge request!619Resolve "Segmentation fault through plugin client"
Pipeline #169268 failed
This commit is part of merge request !619. Comments created here will be created in the context of that merge request.
......@@ -27,6 +27,7 @@ func (m *DeviceModelClient) Unmarshal(json []byte, path *gpb.Path) error {
Json: json,
Path: path,
})
return err
}
......@@ -38,6 +39,7 @@ func (m *DeviceModelClient) SetNode(path *gpb.Path, value *gpb.TypedValue) error
Path: path,
Value: value,
})
return err
}
......@@ -50,7 +52,11 @@ func (m *DeviceModelClient) GetNode(path *gpb.Path, requestForIntendedState bool
Path: path,
RequestForIntendedState: requestForIntendedState,
})
return resp.GetNodes(), err
if err != nil {
return nil, err
}
return resp.GetNodes(), nil
}
// DeleteNode calls the DeleteNode method of the DeviceModelClients client. A
......@@ -60,6 +66,7 @@ func (m *DeviceModelClient) DeleteNode(path *gpb.Path) error {
_, err := m.client.DeleteNode(context.Background(), &pb.DeleteNodeRequest{
Path: path,
})
return err
}
......@@ -71,7 +78,11 @@ func (m *DeviceModelClient) Model(filterReadOnly bool) ([]byte, error) {
resp, err := m.client.Model(context.Background(), &pb.ModelRequest{
FilterReadOnly: filterReadOnly,
})
return resp.Json, err
if err != nil {
return nil, err
}
return resp.Json, nil
}
// Diff calls the Diff method of the DeviceModelClients client. A request is
......@@ -82,7 +93,11 @@ func (m *DeviceModelClient) Diff(original, modified []byte) (*gpb.Notification,
Original: original,
Modified: modified,
})
return resp.GetNotification(), err
if err != nil {
return nil, err
}
return resp.GetNotification(), nil
}
// ValidateChange calls the ValidateChange method of the DeviceModelClients
......@@ -95,7 +110,11 @@ func (m *DeviceModelClient) ValidateChange(operation mnepb.ApiOperation, path *g
Path: path,
Value: value,
})
return resp.GetModel(), err
if err != nil {
return nil, err
}
return resp.GetModel(), nil
}
// PruneConfigFalse calls the PruneConfigFalse method of the DeviceModelClients
......@@ -106,6 +125,10 @@ func (m *DeviceModelClient) PruneConfigFalse(value []byte) ([]byte, error) {
resp, err := m.client.PruneConfigFalse(context.Background(), &pb.PruneConfigFalseRequest{
Value: value,
})
if err != nil {
return nil, err
}
return resp.GetModel(), err
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment