-
Notifications
You must be signed in to change notification settings - Fork 0
/
errors.go
47 lines (38 loc) · 1.16 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
// Package gke implements helper methods to create and list GKE cluster
package gke
import "fmt"
// UnknownError indicates that an unknown error has happened
type UnknownError struct {
Message string
Err error
}
// Error returns message for the UnknownError error type
// Returns the error nessage
func (e UnknownError) Error() string {
if e.Err == nil {
return fmt.Sprintf("Unknown error occurred. Error message: %s.", e.Message)
}
return fmt.Sprintf("Unknown error occurred. Error message: %s. Error: %v", e.Message, e.Err)
}
// Unwrap returns the err if provided through NewUnknownErrorWithError function, otherwise returns nil
func (e UnknownError) Unwrap() error {
return e.Err
}
// IsUnknownError indicates whether the error is of type UnknownError
func IsUnknownError(err error) bool {
_, ok := err.(UnknownError)
return ok
}
// NewUnknownError creates a new UnknownError error
func NewUnknownError(message string) error {
return UnknownError{
Message: message,
}
}
// NewUnknownErrorWithError creates a new UnknownError error
func NewUnknownErrorWithError(message string, err error) error {
return UnknownError{
Message: message,
Err: err,
}
}