github.com/alloyzeus/go-azfl@v0.0.0-20231220071816-9740126a2d07/errors/data/errors.go (about)

     1  // Package data is deprecated. Use the ones from parent package instead.
     2  package data
     3  
     4  // Error is an abstract error type for all data-related errors.
     5  type Error interface {
     6  	error
     7  	ValueError() Error
     8  }
     9  
    10  func Err(err error) Error { return &wrappingError{err} }
    11  
    12  type wrappingError struct {
    13  	err error
    14  }
    15  
    16  var _ Error = &wrappingError{}
    17  
    18  func (e *wrappingError) Error() string     { return e.err.Error() }
    19  func (e *wrappingError) ValueError() Error { return e }
    20  
    21  type msgError struct {
    22  	msg string
    23  }
    24  
    25  var _ Error = &msgError{}
    26  
    27  func (e *msgError) Error() string     { return e.msg }
    28  func (e *msgError) ValueError() Error { return e }
    29  
    30  func Malformed(err error) Error {
    31  	return &malformedError{err}
    32  }
    33  
    34  type malformedError struct {
    35  	err error
    36  }
    37  
    38  var _ Error = &malformedError{}
    39  
    40  func (e *malformedError) Error() string {
    41  	if e.err != nil {
    42  		return "malformed: " + e.err.Error()
    43  	}
    44  	return "malformed"
    45  }
    46  
    47  func (e *malformedError) ValueError() Error { return e }
    48  
    49  var (
    50  	ErrEmpty           = &msgError{"empty"}
    51  	ErrMalformed       = Malformed(nil)
    52  	ErrTypeUnsupported = &msgError{"type unsupported"}
    53  )