Skip to content
Snippets Groups Projects
errors.go 8.13 KiB
Newer Older
  • Learn to ignore specific revisions
  • Manuel Kieweg's avatar
    Manuel Kieweg committed
    import (
    	"fmt"
    	"reflect"
    
    
    	"github.com/openconfig/ygot/ygot"
    
    Manuel Kieweg's avatar
    Manuel Kieweg committed
    )
    
    // NilClientError implements the Error interface and is called if a GNMI Client is nil.
    type NilClientError struct {
    
    	return fmt.Sprint("client cannot be nil")
    
    // NilError implements the Error interface and is called if a struct is nil.
    type NilError struct {
    
    	return fmt.Sprint("struct cannot be nil")
    
    // AlreadyExistsError implements the Error interface and is called if a specific ID
    
    Malte Bauch's avatar
    Malte Bauch committed
    // of a storable item already exists.
    
    	Item interface{}
    
    	return fmt.Sprintf("%T %v already exists", e.Item, e.Item)
    
    // InvalidUUIDError implements the Error interface and is called if a UUID is not valid.
    type InvalidUUIDError struct {
    
    	NetworkElementName string
    
    	return fmt.Sprint("UUID not valid")
    
    // InvalidTypeAssertionError implements the Error interface and is called if the
    
    Malte Bauch's avatar
    Malte Bauch committed
    // type of a storable item does not correspond to the expected type.
    
    	Value interface{}
    	Type  interface{}
    
    func (e InvalidTypeAssertionError) Error() string {
    
    	return fmt.Sprintf("%v does not implement %v", reflect.TypeOf(e.Value).Elem(), reflect.TypeOf(e.Type).Elem())
    
    // UnsupportedPathError implements the Error interface and is called if the
    
    Malte Bauch's avatar
    Malte Bauch committed
    // given path is not supported.
    
    	Path interface{}
    
    	return fmt.Sprintf("path %v is not supported", e.Path)
    
    // PathNotFoundError implements the Error interface and is called if the
    
    // given path is not supported.
    
    	return fmt.Sprintf("path %v not found: %v", e.Path, e.Err)
    }
    
    
    // NotYetImplementedError implements the Error interface and is called if a function
    
    Malte Bauch's avatar
    Malte Bauch committed
    // is not implemented yet.
    
    	return fmt.Sprint("function not yet implemented")
    
    // InvalidParametersError implements the Error interface and is called if the wrong
    
    Malte Bauch's avatar
    Malte Bauch committed
    // or no parameters have been provided.
    
    	Func  interface{}
    	Param interface{}
    
    	return fmt.Sprintf("invalid parameters for %v: %v", e.Func, e.Param)
    
    // InvalidTransportOptionsError implements the Error interface and is called if the
    
    Malte Bauch's avatar
    Malte Bauch committed
    // wrong TransportOptions have been provided.
    
    	Opt interface{}
    
    func (e InvalidTransportOptionsError) Error() string {
    
    	return fmt.Sprintf("invalid transport options: %v", reflect.TypeOf(e.Opt))
    
    // OperationNotSupportedError implements the Error interface and is called if the
    
    // wrong Operation has been provided.
    
    	Op interface{}
    
    func (e OperationNotSupportedError) Error() string {
    
    	return fmt.Sprintf("transport operation not supported: %v", reflect.TypeOf(e.Op))
    
    // UnsupportedSbiTypeError implements the Error interface and is called if the
    
    // wrong Type for a SBI has been provided.
    
    	return fmt.Sprintf("SBI type not supported: %v", e.Type)
    }
    
    
    // PluginVersionError implements the Error interface and is called if the Version
    
    // of a Plugin is older than a Plugin in use.
    
    	return fmt.Sprintf("Version of Plugin: %s is older than the one in use. Provided: %s, in use: %s", e.PlugID, e.ProvidedVer, e.UsedVer)
    }
    
    
    // CombinedErrListError implements the Error interface and is called if a slice of errors
    
    // should be returned. The slice of errors is combined into a single error
    // message and returned.
    
    	combinedErrString := "Errors found:"
    	for i, err := range e.Errors {
    		errString := fmt.Sprintf("\n %v. %v", i+1, err)
    		combinedErrString = combinedErrString + errString
    	}
    	return combinedErrString
    }
    
    
    // TypeNotSupportedError implements the Error interface and is called if the
    
    Fabian Seidl's avatar
    Fabian Seidl committed
    // wrong Type has been provided.
    
    Fabian Seidl's avatar
    Fabian Seidl committed
    	Type interface{}
    }
    
    
    Fabian Seidl's avatar
    Fabian Seidl committed
    	return fmt.Sprintf("type not supported: %v", reflect.TypeOf(e.Type))
    }
    
    // CouldNotMarshallError implements Error interface and is called if a
    
    // database response can not be parsed.
    
    	return fmt.Sprintf("could not marshall Identifier: %v of Type: %T, Internal error: %v", e.Identifier, e.Type, e.Err)
    
    // CouldNotUpdateError implements the Error interface and is called if a
    
    	return fmt.Sprintf("could not update Identifier: %v of Type: %T, Internal error: %v", e.Identifier, e.Type, e.Err)
    
    // CouldNotFindError implements the Error interface and is called if a
    
    	return fmt.Sprintf("ID: %v or Name: %v not found", e.ID, e.Name)
    
    // CouldNotCreateError implements the Error interface and is called if a
    
    	return fmt.Sprintf("could not create Identifier: %v of Type: %T, Internal error: %v", e.Identifier, e.Type, e.Err)
    
    // CouldNotDeleteError implements the Error interface and is called if a
    
    // stored item can not be deleted.
    
    	return fmt.Sprintf("could not delete Identifier: %v of Type: %T, Internal error: %v", e.Identifier, e.Type, e.Err)
    
    // NoNewChangesError implements the Error interface and is called if a the
    
    // gNMI-Notification created from ygot.Diff does not contain any `updates` or
    // `deletes`.
    
    	Original ygot.GoStruct
    	Modified ygot.GoStruct
    }
    
    
    	return fmt.Sprintf("There are no changes between %v and %v", e.Original, e.Modified)
    }
    
    // AMQPInitFailError implements the Error interface and is called if there is any issue related to
    
    	return fmt.Sprintf("Action: %s, Internal error: %v", e.Action, e.Err)
    }
    
    
    // AMQPMessageFailError implements the Error interface and is called if there is any issue with sending
    
    	return fmt.Sprintf("Action: %s, Internal error: %v", e.Action, e.Err)
    }
    
    // SubscribeResponseError implements the Error interface and is called if there is an issue during a ongoing
    
    	PndID              string
    	NetworkElementID   string
    	NetworkElementName string
    	Err                string
    
    	return fmt.Sprintf("Subscribe failed, PndID: %s, NetworkElementID: %s, NetworkElementName: %s, Internal error: %s", e.PndID, e.NetworkElementID, e.NetworkElementName, e.Err)
    
    // SubscribeSyncResponseError implements the Error interface and is called if there is an issue syncing a
    
    	PndID              string
    	NetworkElementID   string
    	NetworkElementName string
    
    func (e SubscribeSyncResponseError) Error() string {
    
    	return fmt.Sprintf("Sync failed, PndID: %s, NetworkElementID: %s, NetworkElementName: %s", e.PndID, e.NetworkElementID, e.NetworkElementName)