diff --git a/nucleus/errors/errors.go b/nucleus/errors/errors.go index d85599bf829d5705a09c71783615fc27150bae7f..43bce0f1d71ae60e66d9f0288e1c4ad21632f42b 100644 --- a/nucleus/errors/errors.go +++ b/nucleus/errors/errors.go @@ -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 diff --git a/nucleus/gnmi_transport.go b/nucleus/gnmi_transport.go index 8b56dc80e65254f9e95d7ab555ffb6b0a1f1b4cc..37f6f772680f4de808f51b75c663fc14040e99b0 100644 --- a/nucleus/gnmi_transport.go +++ b/nucleus/gnmi_transport.go @@ -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() { diff --git a/nucleus/principalNetworkDomain.go b/nucleus/principalNetworkDomain.go index b5dd33d7afc4d691cf6bde7f47a1b59895538a8a..94a3143622f6d2d11a07fed5bef7f727788922aa 100644 --- a/nucleus/principalNetworkDomain.go +++ b/nucleus/principalNetworkDomain.go @@ -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(), diff --git a/nucleus/southbound.go b/nucleus/southbound.go index 7271eb8d408bb60bd6eaf62465be379ecf221b01..d62411738bac97389cbf9173755c35e53a686b80 100644 --- a/nucleus/southbound.go +++ b/nucleus/southbound.go @@ -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 { diff --git a/store/changeStores.go b/store/changeStores.go index 974c6f13eff8e453ee9d05e85639d3d6f7b8e7b0..ef2d5a75002d14399c3e00c5acca0912798dc88f 100644 --- a/store/changeStores.go +++ b/store/changeStores.go @@ -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()) } } } diff --git a/store/deviceStore.go b/store/deviceStore.go index c55927c4e98ff28f6a8e71432d99622a5341b517..871c096f816f301d27174463d4b8122f7374947c 100644 --- a/store/deviceStore.go +++ b/store/deviceStore.go @@ -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{ diff --git a/store/pndStore.go b/store/pndStore.go index b1b8d3fc54f933169ddb238ee2438e42c41c2883..deff904fdf1cea5cba708484164486139fd65977 100644 --- a/store/pndStore.go +++ b/store/pndStore.go @@ -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{ diff --git a/store/sbiStore.go b/store/sbiStore.go index fd8310bfd64577c822748afdbb14b2744a6028de..f74d31092cef87ace0682015110a1a0195f8845b 100644 --- a/store/sbiStore.go +++ b/store/sbiStore.go @@ -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{ diff --git a/test/integration/nucleusIntegration_test.go b/test/integration/nucleusIntegration_test.go index cf7b86936827bf78862ff2f9d1ede030cab5241d..68ac907101bd4fb1dd82c2289821e820c9411030 100644 --- a/test/integration/nucleusIntegration_test.go +++ b/test/integration/nucleusIntegration_test.go @@ -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 {