-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherrors.go
More file actions
66 lines (54 loc) · 1.34 KB
/
errors.go
File metadata and controls
66 lines (54 loc) · 1.34 KB
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
64
65
66
package do
import (
"errors"
"fmt"
"strings"
)
var ErrServiceNotFound = errors.New("DI: could not find service")
var ErrServiceNotMatch = errors.New("DI: could not find service satisfying interface")
var ErrCircularDependency = errors.New("DI: circular dependency detected")
var ErrHealthCheckTimeout = errors.New("DI: health check timeout")
func newShutdownErrors() *ShutdownErrors {
return &ShutdownErrors{}
}
type ShutdownErrors map[EdgeService]error
func (e *ShutdownErrors) Add(scopeID string, scopeName string, serviceName string, err error) {
if err != nil {
(*e)[newEdgeService(scopeID, scopeName, serviceName)] = err
}
}
func (e ShutdownErrors) Len() int {
out := 0
for _, v := range e {
if v != nil {
out++
}
}
return out
}
func (e ShutdownErrors) Error() string {
lines := []string{}
for k, v := range e {
if v != nil {
lines = append(lines, fmt.Sprintf(" - %s > %s: %s", k.ScopeName, k.Service, v.Error()))
}
}
if len(lines) == 0 {
return "DI: no shutdown errors"
}
return "DI: shutdown errors:\n" + strings.Join(lines, "\n")
}
func mergeShutdownErrors(ins ...*ShutdownErrors) *ShutdownErrors {
out := newShutdownErrors()
for _, in := range ins {
if in != nil {
se := &ShutdownErrors{}
if ok := errors.As(in, &se); ok {
for k, v := range *se {
(*out)[k] = v
}
}
}
}
return out
}