-
-
Notifications
You must be signed in to change notification settings - Fork 9
/
errors.go
63 lines (55 loc) · 1.38 KB
/
errors.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package hit
import (
"github.com/Eun/go-hit/errortrace"
)
// Error represents the error that will be returned during an execution.
type Error struct {
callPath callPath
et *errortrace.ErrorTrace
}
// Error returns the string representation for the error.
func (e *Error) Error() string {
return e.et.Error()
}
// Implement xerrors
// Is implements the xerrors interface so we can use the xerrors.Is() function.
func (e *Error) Is(err error) bool {
return e.et == err
}
// Unwrap implements the xerrors.Wrapper interface.
func (e *Error) Unwrap() error {
return e.et
}
// FailingStepIs returns true if the specified step is the same as the failing.
//
// Example:
// err := Do(
// Get("https://example.com"),
// Expect().Status().Equal(http.StatusNoContent),
// )
// var hitError *Error
// if errors.As(err, &hitError) {
// if hitError.FailingStepIs(Expect().Status().Equal(http.StatusNoContent)) {
// fmt.Printf("Expected StatusNoContent")
// return
// }
// }
func (e *Error) FailingStepIs(s IStep) bool {
if e.callPath == nil || s == nil {
return false
}
cp := s.callPath()
if cp == nil {
return false
}
return e.callPath.Equal(cp)
}
func wrapError(hit Hit, err error) *Error {
t := ett.Prepare()
t.SetError(err)
t.SetDescription(hit.Description())
return &Error{
callPath: nil,
et: t,
}
}