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