1
package elemental
2

3
import (
4
	"fmt"
5
	"reflect"
6
)
7

8
// ErrUnsupportedComparator is the error type that will be returned in the event that that an unsupported comparator
9
// is used in the filter.
10
type ErrUnsupportedComparator struct {
11
	Err error
12
}
13

14
// Is reports whether the provided error has the same type as ErrUnsupportedComparator. This was added as part of the new
15
// error handling APIs added to Go 1.13
16
func (e ErrUnsupportedComparator) Is(err error) bool {
17 14
	return reflect.TypeOf(err) == reflect.TypeOf(e)
18
}
19

20
// Unwrap returns the embedded error in ErrUnsupportedComparator.
21
func (e ErrUnsupportedComparator) Unwrap() error {
22 14
	return e.Err
23
}
24

25
func (e ErrUnsupportedComparator) Error() string {
26 14
	return fmt.Sprintf("unsupported comparator: %s", e.Err)
27
}
28

29
// MatcherError is the error type that will be returned by elemental.MatchesFilter in the event that it returns an error
30
type MatcherError struct {
31
	Err error
32
}
33

34
func (me *MatcherError) Error() string {
35 14
	return fmt.Sprintf("elemental: unable to match: %s", me.Err)
36
}
37

38
// Unwrap returns the the error contained in 'MatcherError'. This is a special method that aids in error handling for clients
39
// using Go 1.13 and beyond as they can now utilize the new 'Is' function added to the 'errors' package.
40
func (me *MatcherError) Unwrap() error {
41 14
	return me.Err
42
}

Read our documentation on viewing source code .

Loading