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

Resolve "Custom error values are not provided"

parent f3d9841b
Branches
Tags
5 merge requests!246Develop,!245Develop into Master,!244Master into develop2 into master,!233Resolve "Custom error values are not provided",!138Develop
......@@ -58,7 +58,7 @@ type ErrInvalidTypeAssertion struct {
}
func (e ErrInvalidTypeAssertion) Error() string {
return fmt.Sprintf("%v does not implement %v", e.Value, e.Type)
return fmt.Sprintf("%v does not implement %v", reflect.TypeOf(e.Value).Elem(), reflect.TypeOf(e.Type).Elem())
}
// ErrUnsupportedPath implements the Error interface and is called if the
......
......@@ -3,7 +3,6 @@ package nucleus
import (
"context"
"fmt"
"reflect"
"code.fbi.h-da.de/danet/gosdn/interfaces/change"
......@@ -39,9 +38,15 @@ type Gnmi struct {
// Do not call directly. Use NewTransport() instead.
func newGnmiTransport(opts *tpb.TransportOption, sbi southbound.SouthboundInterface) (*Gnmi, error) {
if opts == nil || sbi == nil {
return nil, &errors.ErrInvalidParameters{}
return nil, &errors.ErrInvalidParameters{
Func: newGnmiTransport,
Param: "'opts' and 'sbi' can not be nil",
}
} else if opts.TransportOption == nil {
return nil, &errors.ErrInvalidParameters{}
return nil, &errors.ErrInvalidParameters{
Func: newGnmiTransport,
Param: "'opts.TransportOption' can not be nil",
}
}
gnmiConfig := &gnmi.Config{
Addr: opts.Address,
......@@ -102,7 +107,7 @@ func (g *Gnmi) applyDiff(ctx context.Context, payload change.Payload) error {
case ppb.ApiOperation_REPLACE:
req.Replace = diff.Update
default:
return &errors.ErrOperationNotSupported{}
return &errors.ErrOperationNotSupported{Op: op}
}
} else if diff.Delete != nil {
req.Delete = diff.Delete
......@@ -131,11 +136,17 @@ func (g *Gnmi) Type() string {
func (g *Gnmi) ProcessResponse(resp interface{}, root interface{}, s *ytypes.Schema) error {
d, ok := root.(ygot.ValidatedGoStruct)
if !ok {
return &errors.ErrInvalidTypeAssertion{}
return &errors.ErrInvalidTypeAssertion{
Value: root,
Type: (*ygot.ValidatedGoStruct)(nil),
}
}
r, ok := resp.(*gpb.GetResponse)
if !ok {
return &errors.ErrInvalidTypeAssertion{}
return &errors.ErrInvalidTypeAssertion{
Value: resp,
Type: &gpb.GetResponse{},
}
}
rn := r.Notification
errs := make([]error, 0)
......@@ -219,8 +230,8 @@ func (g *Gnmi) subscribe(ctx context.Context) error {
opts, ok := ctx.Value(types.CtxKeyOpts).(*gnmi.SubscribeOptions)
if !ok {
return &errors.ErrInvalidTypeAssertion{
Value: reflect.TypeOf(ctx.Value(types.CtxKeyOpts)),
Type: reflect.TypeOf(&gnmi.SubscribeOptions{}),
Value: ctx.Value(types.CtxKeyOpts),
Type: &gnmi.SubscribeOptions{},
}
}
go func() {
......
......@@ -290,7 +290,10 @@ func (pnd *pndImplementation) Request(uuid uuid.UUID, path string) (proto.Messag
}
resp, ok := res.(proto.Message)
if !ok {
return nil, &errors.ErrInvalidTypeAssertion{}
return nil, &errors.ErrInvalidTypeAssertion{
Value: res,
Type: (*proto.Message)(nil),
}
}
err = d.ProcessResponse(resp)
if err != nil {
......@@ -515,7 +518,10 @@ func loadPlugin(id uuid.UUID) (southbound.SouthboundInterface, error) {
var sbi southbound.SouthboundInterface
sbi, ok := symbol.(southbound.SouthboundInterface)
if !ok {
return nil, &errors.ErrInvalidTypeAssertion{}
return nil, &errors.ErrInvalidTypeAssertion{
Value: symbol,
Type: (*southbound.SouthboundInterface)(nil),
}
}
log.WithFields(log.Fields{
"identifier": sbi.SbiIdentifier(),
......
......@@ -91,7 +91,10 @@ func unmarshal(schema *ytypes.Schema, bytes []byte, path *gpb.Path, goStruct ygo
}
validatedDeepCopy, ok := root.(ygot.ValidatedGoStruct)
if !ok {
return &errors.ErrInvalidTypeAssertion{}
return &errors.ErrInvalidTypeAssertion{
Value: root,
Type: (*ygot.ValidatedGoStruct)(nil),
}
}
// returns the node we want to fill with the data contained in 'bytes',
......@@ -102,7 +105,10 @@ func unmarshal(schema *ytypes.Schema, bytes []byte, path *gpb.Path, goStruct ygo
}
validatedCreatedNode, ok := createdNode.(ygot.ValidatedGoStruct)
if !ok {
return &errors.ErrInvalidTypeAssertion{}
return &errors.ErrInvalidTypeAssertion{
Value: createdNode,
Type: (*ygot.ValidatedGoStruct)(nil),
}
}
if err := openconfig.Unmarshal(bytes, validatedCreatedNode, opt...); err != nil {
......
......@@ -26,17 +26,17 @@ func (s *ChangeStore) GetChange(id uuid.UUID) (change.Change, error) {
if err != nil {
return nil, err
}
change, ok := item.(change.Change)
c, ok := item.(change.Change)
if !ok {
return nil, &errors.ErrInvalidTypeAssertion{
Value: change,
Type: "change",
Value: c,
Type: (*change.Change)(nil),
}
}
log.WithFields(log.Fields{
"uuid": id,
}).Debug("change was accessed")
return change, nil
return c, nil
}
// Pending returns the UUIDs of all pending changes
......@@ -57,10 +57,10 @@ func (s *ChangeStore) Confirmed() []uuid.UUID {
func filterChanges(store *ChangeStore, state ppb.Change_State) []uuid.UUID {
changes := make([]uuid.UUID, 0)
for _, ch := range store.Store {
switch change := ch.(type) {
switch c := ch.(type) {
case change.Change:
if change.State() == state {
changes = append(changes, change.ID())
if c.State() == state {
changes = append(changes, c.ID())
}
}
}
......
......@@ -44,7 +44,7 @@ func (s *DeviceStore) GetDevice(id uuid.UUID, parseErrors ...error) (device.Devi
myID, ok := s.DeviceNameToUUIDLookup[e.DeviceName]
if !ok {
log.Debug(fmt.Sprintf("no device named %s found", foundID))
return nil, &errors.ErrNotFound{}
return nil, &errors.ErrNotFound{ID: foundID}
}
foundID = myID
......@@ -60,7 +60,7 @@ func (s *DeviceStore) GetDevice(id uuid.UUID, parseErrors ...error) (device.Devi
if !ok {
return nil, &errors.ErrInvalidTypeAssertion{
Value: d,
Type: reflect.TypeOf((device.Device)(nil)),
Type: (*device.Device)(nil),
}
}
log.WithFields(log.Fields{
......
......@@ -47,7 +47,7 @@ func (s *PndStore) GetPND(id uuid.UUID) (networkdomain.NetworkDomain, error) {
if !ok {
return nil, &errors.ErrInvalidTypeAssertion{
Value: pnd,
Type: "PrincipalNetworkDomain",
Type: (*networkdomain.NetworkDomain)(nil),
}
}
log.WithFields(log.Fields{
......
......@@ -29,7 +29,7 @@ func (s *SbiStore) GetSBI(id uuid.UUID) (southbound.SouthboundInterface, error)
if !ok {
return nil, &errors.ErrInvalidTypeAssertion{
Value: sbi,
Type: "SouthboundInterface",
Type: (*southbound.SouthboundInterface)(nil),
}
}
log.WithFields(log.Fields{
......
......@@ -228,7 +228,10 @@ func TestGnmi_SetValidIntegration(t *testing.T) {
}
r, ok := resp.(*gpb.GetResponse)
if !ok {
t.Error(&errors.ErrInvalidTypeAssertion{})
t.Error(&errors.ErrInvalidTypeAssertion{
Value: resp,
Type: &gpb.GetResponse{},
})
return
}
got := r.Notification[0].Update[0].Val.GetStringVal()
......@@ -485,7 +488,10 @@ func TestGnmi_CapabilitiesIntegration(t *testing.T) {
}
g, ok := tr.(*nucleus.Gnmi)
if !ok {
t.Error(&errors.ErrInvalidTypeAssertion{})
t.Error(&errors.ErrInvalidTypeAssertion{
Value: tr,
Type: &nucleus.Gnmi{},
})
}
resp, err := g.Capabilities(tt.args.ctx)
if (err != nil) != tt.wantErr {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment