Skip to content
Snippets Groups Projects
errors.go 2.9 KiB
Newer Older
  • Learn to ignore specific revisions
  • package errors
    
    Manuel Kieweg's avatar
    Manuel Kieweg committed
    import (
    	"fmt"
    	"reflect"
    )
    
    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.Sprintf("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.Sprintf("struct cannot be nil")
    }
    
    
    Malte Bauch's avatar
    Malte Bauch committed
    // ErrNotFound implements the Error interface and is called if a specific ID
    // of a storable item could not be found.
    
    type ErrNotFound struct {
    
    	ID interface{}
    
    func (e *ErrNotFound) Error() string {
    
    	return fmt.Sprintf("%v not found", e.ID)
    
    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("%v already exists", 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.Sprintf("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", e.Value, e.Type)
    
    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)
    
    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.Sprintf("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))