/
errors.go
63 lines (53 loc) · 1.74 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 v1
import (
"errors"
"fmt"
)
const (
// PodNotFound is an error that pod is not found
PodNotFound = "PodNotFound"
// ContainerNotFound is an error that container is not found
ContainerNotFound = "ContainerNotFound"
// ContainerStatusIsNil is an error that container status is nil
ContainerStatusIsNil = "ContainerStatusIsNil"
// PodNotRunning is an error that pod is not running
PodNotRunning = "PodNotRunning"
// PvcVolumeMountNotFound is an error that PVC volume mount is not found in pod
PvcVolumeMountNotFound = "PvcVolumeMountNotFound"
// PvcVolumeNotFound is an error that volume is not found in pod
PvcVolumeNotFound = "PvcVolumeNotFound"
)
// RegistryErrors represents error of registry subresource
type RegistryErrors struct {
errorType *string
errorMessage *string
}
func (r RegistryErrors) Error() string {
if r.errorType != nil {
return *r.errorType
}
return *r.errorMessage
}
// MakeRegistryError sets error of registry subresource
func MakeRegistryError(e string) error {
RegistryError := RegistryErrors{}
if e == PodNotFound || e == ContainerNotFound || e == ContainerStatusIsNil || e == PodNotRunning || e == PvcVolumeMountNotFound {
RegistryError.errorType = &e
} else {
RegistryError.errorMessage = &e
}
return RegistryError
}
// IsPodError returns true if the specified error was created by PodNotFound, ContainerStatusIsNil, or PodNotRunning.
func IsPodError(err error) bool {
if err.Error() == PodNotFound || err.Error() == ContainerStatusIsNil || err.Error() == PodNotRunning {
return true
}
return false
}
func AppendError(err error, appendMessage string) error {
if err == nil || err.Error() == "" {
return errors.New(appendMessage)
}
return fmt.Errorf("%s, %s", err.Error(), appendMessage)
}