Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
aos
GitHub Repository: aos/grafana-agent
Path: blob/main/pkg/metrics/instance/errors.go
4094 views
1
package instance
2
3
import "fmt"
4
5
// ErrInvalidUpdate is returned whenever Update is called against an instance
6
// but an invalid field is changed between configs. If ErrInvalidUpdate is
7
// returned, the instance must be fully stopped and replaced with a new one
8
// with the new config.
9
type ErrInvalidUpdate struct {
10
Inner error
11
}
12
13
// Error implements the error interface.
14
func (e ErrInvalidUpdate) Error() string { return e.Inner.Error() }
15
16
// Is returns true if err is an ErrInvalidUpdate.
17
func (e ErrInvalidUpdate) Is(err error) bool {
18
switch err.(type) {
19
case ErrInvalidUpdate, *ErrInvalidUpdate:
20
return true
21
default:
22
return false
23
}
24
}
25
26
// As will set the err object to ErrInvalidUpdate provided err
27
// is a pointer to ErrInvalidUpdate.
28
func (e ErrInvalidUpdate) As(err interface{}) bool {
29
switch v := err.(type) {
30
case *ErrInvalidUpdate:
31
*v = e
32
default:
33
return false
34
}
35
return true
36
}
37
38
// errImmutableField is the error describing a field that cannot be changed. It
39
// is wrapped inside of a ErrInvalidUpdate.
40
type errImmutableField struct{ Field string }
41
42
func (e errImmutableField) Error() string {
43
return fmt.Sprintf("%s cannot be changed dynamically", e.Field)
44
}
45
46