Skip to content
Snippets Groups Projects
errors.go 7.83 KiB
Newer Older
  • Learn to ignore specific revisions
  • package errors
    
    Manuel Kieweg's avatar
    Manuel Kieweg committed
    import (
    	"fmt"
    	"reflect"
    
    
    	"github.com/openconfig/ygot/ygot"
    
    Manuel Kieweg's avatar
    Manuel Kieweg committed
    )
    
    Malte Bauch's avatar
    Malte Bauch committed
    // ErrNilClient implements the Error interface and is called if a GNMI Client is nil.
    
    type ErrNilClient struct {
    }
    
    
    func (e *ErrNilClient) Error() string {
    
    	return fmt.Sprint("client cannot be nil")
    
    Malte Bauch's avatar
    Malte Bauch committed
    // ErrNil implements the Error interface and is called if a struct is nil.
    
    Manuel Kieweg's avatar
    Manuel Kieweg committed
    type ErrNil struct {
    }
    
    func (e *ErrNil) Error() string {
    
    	return fmt.Sprint("struct cannot be nil")
    
    Malte Bauch's avatar
    Malte Bauch committed
    // ErrAlreadyExists implements the Error interface and is called if a specific ID
    // of a storable item already exists.
    
    type ErrAlreadyExists struct {
    
    	Item interface{}
    
    }
    
    func (e *ErrAlreadyExists) Error() string {
    
    	return fmt.Sprintf("%T %v already exists", e.Item, e.Item)
    
    // ErrInvalidUUID implements the Error interface and is called if a UUID is not valid.
    type ErrInvalidUUID struct {
    	DeviceName string
    }
    
    func (e *ErrInvalidUUID) Error() string {
    
    	return fmt.Sprint("UUID not valid")
    
    Malte Bauch's avatar
    Malte Bauch committed
    // ErrInvalidTypeAssertion implements the Error interface and is called if the
    // type of a storable item does not correspond to the expected type.
    
    type ErrInvalidTypeAssertion struct {
    
    	Value interface{}
    	Type  interface{}
    
    }
    
    func (e ErrInvalidTypeAssertion) Error() string {
    
    	return fmt.Sprintf("%v does not implement %v", reflect.TypeOf(e.Value).Elem(), reflect.TypeOf(e.Type).Elem())
    
    Malte Bauch's avatar
    Malte Bauch committed
    // ErrUnsupportedPath implements the Error interface and is called if the
    // given path is not supported.
    
    Manuel Kieweg's avatar
    Manuel Kieweg committed
    type ErrUnsupportedPath struct {
    
    	Path interface{}
    
    Manuel Kieweg's avatar
    Manuel Kieweg committed
    }
    
    func (e ErrUnsupportedPath) Error() string {
    
    	return fmt.Sprintf("path %v is not supported", e.Path)
    
    // ErrPathNotFound implements the Error interface and is called if the
    // given path is not supported.
    type ErrPathNotFound struct {
    	Path interface{}
    	Err  error
    }
    
    func (e ErrPathNotFound) Error() string {
    	return fmt.Sprintf("path %v not found: %v", e.Path, e.Err)
    }
    
    
    Malte Bauch's avatar
    Malte Bauch committed
    // ErrNotYetImplemented implements the Error interface and is called if a function
    // is not implemented yet.
    
    Manuel Kieweg's avatar
    Manuel Kieweg committed
    type ErrNotYetImplemented struct{}
    
    func (e ErrNotYetImplemented) Error() string {
    
    	return fmt.Sprint("function not yet implemented")
    
    Malte Bauch's avatar
    Malte Bauch committed
    // ErrInvalidParameters implements the Error interface and is called if the wrong
    // or no parameters have been provided.
    
    Manuel Kieweg's avatar
    Manuel Kieweg committed
    type ErrInvalidParameters struct {
    
    	Func  interface{}
    	Param interface{}
    
    Manuel Kieweg's avatar
    Manuel Kieweg committed
    }
    
    func (e ErrInvalidParameters) Error() string {
    
    	return fmt.Sprintf("invalid parameters for %v: %v", e.Func, e.Param)
    
    Malte Bauch's avatar
    Malte Bauch committed
    // ErrInvalidTransportOptions implements the Error interface and is called if the
    // wrong TransportOptions have been provided.
    
    Manuel Kieweg's avatar
    Manuel Kieweg committed
    type ErrInvalidTransportOptions struct {
    
    	Opt interface{}
    
    Manuel Kieweg's avatar
    Manuel Kieweg committed
    }
    
    func (e ErrInvalidTransportOptions) Error() string {
    
    	return fmt.Sprintf("invalid transport options: %v", reflect.TypeOf(e.Opt))
    
    
    // ErrOperationNotSupported implements the Error interface and is called if the
    // wrong Operation has been provided.
    type ErrOperationNotSupported struct {
    
    	Op interface{}
    
    }
    
    func (e ErrOperationNotSupported) Error() string {
    
    	return fmt.Sprintf("transport operation not supported: %v", reflect.TypeOf(e.Op))
    
    // ErrUnsupportedSbiType implements the Error interface and is called if the
    // wrong Type for a SBI has been provided.
    type ErrUnsupportedSbiType struct {
    	Type interface{}
    }
    
    func (e ErrUnsupportedSbiType) Error() string {
    	return fmt.Sprintf("SBI type not supported: %v", e.Type)
    }
    
    // ErrPluginVersion implements the Error interface and is called if the Version
    // of a Plugin is older than a Plugin in use.
    type ErrPluginVersion struct {
    	PlugID, ProvidedVer, UsedVer string
    }
    
    func (e ErrPluginVersion) Error() string {
    	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)
    }
    
    // ErrorList 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.
    type ErrorList struct {
    	Errors []error
    }
    
    func (e ErrorList) Error() string {
    	combinedErrString := "Errors found:"
    	for i, err := range e.Errors {
    		errString := fmt.Sprintf("\n %v. %v", i+1, err)
    		combinedErrString = combinedErrString + errString
    	}
    	return combinedErrString
    }
    
    
    Fabian Seidl's avatar
    Fabian Seidl committed
    // ErrTypeNotSupported implements the Error interface and is called if the
    // wrong Type has been provided.
    type ErrTypeNotSupported struct {
    	Type interface{}
    }
    
    func (e ErrTypeNotSupported) Error() string {
    	return fmt.Sprintf("type not supported: %v", reflect.TypeOf(e.Type))
    }
    
    
    // ErrCouldNotMarshall implements Error interface and is called if a
    // database respone can not be parsed.
    type ErrCouldNotMarshall struct {
    
    }
    
    func (e ErrCouldNotMarshall) Error() string {
    
    	return fmt.Sprintf("could not marshall Identifier: %v of Type: %T, Internal error: %v", e.Identifier, e.Type, e.Err)
    
    }
    
    // ErrCouldNotUpdate implements the Error interface and is called if a
    // stored item can not be updated.
    type ErrCouldNotUpdate struct {
    
    }
    
    func (e ErrCouldNotUpdate) Error() string {
    
    	return fmt.Sprintf("could not update Identifier: %v of Type: %T, Internal error: %v", e.Identifier, e.Type, e.Err)
    
    }
    
    // ErrCouldNotFind implements the Error interface and is called if a
    // stored item can not be found.
    type ErrCouldNotFind struct {
    
    	return fmt.Sprintf("ID: %v or Name: %v not found", e.ID, e.Name)
    
    }
    
    // ErrCouldNotCreate implements the Error interface and is called if a
    // stored item can not be found.
    type ErrCouldNotCreate struct {
    
    }
    
    func (e ErrCouldNotCreate) Error() string {
    
    	return fmt.Sprintf("could not create Identifier: %v of Type: %T, Internal error: %v", e.Identifier, e.Type, e.Err)
    
    
    // ErrCouldNotDelete implements the Error interface and is called if a
    // stored item can not be deleted.
    type ErrCouldNotDelete struct {
    
    }
    
    func (e ErrCouldNotDelete) Error() string {
    
    	return fmt.Sprintf("could not delete Identifier: %v of Type: %T, Internal error: %v", e.Identifier, e.Type, e.Err)
    
    
    // ErrNoNewChanges implements the Error interface and is called if a the
    // gNMI-Notification created from ygot.Diff does not contain any `updates` or
    // `deletes`.
    type ErrNoNewChanges struct {
    	Original ygot.GoStruct
    	Modified ygot.GoStruct
    }
    
    func (e ErrNoNewChanges) Error() string {
    	return fmt.Sprintf("There are no changes between %v and %v", e.Original, e.Modified)
    }
    
    
    // ErrAMQPInitFail implements the Error interface and is called if there is any issue related to
    // the setup of the event management.
    type ErrAMQPInitFail struct {
    	Action string
    	Err    error
    }
    
    func (e ErrAMQPInitFail) Error() string {
    	return fmt.Sprintf("Action: %s, Internal error: %v", e.Action, e.Err)
    }
    
    // ErrAMQPMessageFail implements the Error interface and is called if there is any issue with sending
    // or receiving messages.
    type ErrAMQPMessageFail struct {
    	Action string
    	Err    error
    }
    
    func (e ErrAMQPMessageFail) Error() string {
    	return fmt.Sprintf("Action: %s, Internal error: %v", e.Action, e.Err)
    }
    
    
    // ErrSubscribeResponse implements the Error interface and is called if there is an issue during a ongoing
    // gNMI Subscription.
    type ErrSubscribeResponse struct {
    	PndID      string
    	DeviceID   string
    	DeviceName string
    	Err        string
    }
    
    func (e ErrSubscribeResponse) Error() string {
    	return fmt.Sprintf("Subscribe failed, PndID: %s, DeviceID: %s, DeviceName: %s, Internal error: %s", e.PndID, e.DeviceID, e.DeviceName, e.Err)
    }
    
    // ErrSubscribeSyncResponse implements the Error interface and is called if there is an issue syncing a
    // gNMI Subscription.
    type ErrSubscribeSyncResponse struct {
    	PndID      string
    	DeviceID   string
    	DeviceName string
    }
    
    func (e ErrSubscribeSyncResponse) Error() string {
    	return fmt.Sprintf("Sync failed, PndID: %s, DeviceID: %s, DeviceName: %s", e.PndID, e.DeviceID, e.DeviceName)
    }