-
Notifications
You must be signed in to change notification settings - Fork 487
/
errors.go
44 lines (37 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
package instance
import "fmt"
// ErrInvalidUpdate is returned whenever Update is called against an instance
// but an invalid field is changed between configs. If ErrInvalidUpdate is
// returned, the instance must be fully stopped and replaced with a new one
// with the new config.
type ErrInvalidUpdate struct {
Inner error
}
// Error implements the error interface.
func (e ErrInvalidUpdate) Error() string { return e.Inner.Error() }
// Is returns true if err is an ErrInvalidUpdate.
func (e ErrInvalidUpdate) Is(err error) bool {
switch err.(type) {
case ErrInvalidUpdate, *ErrInvalidUpdate:
return true
default:
return false
}
}
// As will set the err object to ErrInvalidUpdate provided err
// is a pointer to ErrInvalidUpdate.
func (e ErrInvalidUpdate) As(err interface{}) bool {
switch v := err.(type) {
case *ErrInvalidUpdate:
*v = e
default:
return false
}
return true
}
// errImmutableField is the error describing a field that cannot be changed. It
// is wrapped inside of a ErrInvalidUpdate.
type errImmutableField struct{ Field string }
func (e errImmutableField) Error() string {
return fmt.Sprintf("%s cannot be changed dynamically", e.Field)
}