github.com/yankunsam/loki/v2@v2.6.3-0.20220817130409-389df5235c27/pkg/ruler/storage/instance/errors.go (about)

     1  // This directory was copied and adapted from https://github.com/grafana/agent/tree/main/pkg/metrics.
     2  // We cannot vendor the agent in since the agent vendors loki in, which would cause a cyclic dependency.
     3  // NOTE: many changes have been made to the original code for our use-case.
     4  package instance
     5  
     6  import "fmt"
     7  
     8  // ErrInvalidUpdate is returned whenever Update is called against an instance
     9  // but an invalid field is changed between configs. If ErrInvalidUpdate is
    10  // returned, the instance must be fully stopped and replaced with a new one
    11  // with the new config.
    12  type ErrInvalidUpdate struct {
    13  	Inner error
    14  }
    15  
    16  // Error implements the error interface.
    17  func (e ErrInvalidUpdate) Error() string { return e.Inner.Error() }
    18  
    19  // Is returns true if err is an ErrInvalidUpdate.
    20  func (e ErrInvalidUpdate) Is(err error) bool {
    21  	switch err.(type) {
    22  	case ErrInvalidUpdate, *ErrInvalidUpdate:
    23  		return true
    24  	default:
    25  		return false
    26  	}
    27  }
    28  
    29  // As will set the err object to ErrInvalidUpdate provided err
    30  // is a pointer to ErrInvalidUpdate.
    31  func (e ErrInvalidUpdate) As(err interface{}) bool {
    32  	switch v := err.(type) {
    33  	case *ErrInvalidUpdate:
    34  		*v = e
    35  	default:
    36  		return false
    37  	}
    38  	return true
    39  }
    40  
    41  // errImmutableField is the error describing a field that cannot be changed. It
    42  // is wrapped inside of a ErrInvalidUpdate.
    43  type errImmutableField struct{ Field string }
    44  
    45  func (e errImmutableField) Error() string {
    46  	return fmt.Sprintf("%s cannot be changed dynamically", e.Field)
    47  }