-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherrors.go
62 lines (50 loc) · 1.51 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
package simular
import (
"fmt"
"strings"
)
// ErrNoResponderFound is a custom error type used when no responders were
// found.
type ErrNoResponderFound struct {
errs []error
}
// Error ensures our ErrNoResponderFound type implements the error interface
func (e *ErrNoResponderFound) Error() string {
if len(e.errs) == 0 {
return "No responders found"
}
errMsgs := []string{}
for _, e := range e.errs {
errMsgs = append(errMsgs, e.Error())
}
return fmt.Sprintf("Responder errors: %s", strings.Join(errMsgs, ", "))
}
// NewErrNoResponderFound returns a new ErrNoResponderFound error
func NewErrNoResponderFound(errs []error) *ErrNoResponderFound {
return &ErrNoResponderFound{
errs: errs,
}
}
// ErrStubsNotCalled is a type implementing the error interface we return when
// not all registered stubs were called
type ErrStubsNotCalled struct {
uncalledStubs []*StubRequest
}
// Error ensures our ErrStubsNotCalled type implements the error interface
func (e *ErrStubsNotCalled) Error() string {
// TODO: is there a better way of giving a rich error message than this?
if len(e.uncalledStubs) == 0 {
return "No registered stubs"
}
uncalled := []string{}
for _, s := range e.uncalledStubs {
uncalled = append(uncalled, s.String())
}
return fmt.Sprintf("Uncalled stubs: %s", strings.Join(uncalled, ", "))
}
// NewErrStubsNotCalled returns a new StubsNotCalled error
func NewErrStubsNotCalled(uncalledStubs []*StubRequest) *ErrStubsNotCalled {
return &ErrStubsNotCalled{
uncalledStubs: uncalledStubs,
}
}