Documentation
¶
Overview ¶
Package errors centralises error types and sentinel values for the replication subsystem. All packages that need to produce or inspect replica errors should import this package rather than defining their own.
Index ¶
Constants ¶
const MsgCLevel = "cannot achieve consistency level"
MsgCLevel is the human-readable prefix used in consistency-level errors.
Variables ¶
var ( // ErrReplicas is the canonical sentinel for "not enough replicas were // reachable". It is intentionally kept simple so that callers can rely // on errors.Is for detection while richer wrapper types carry the // underlying cause. ErrReplicas = errors.New("cannot reach enough replicas") // ErrRepair is the canonical sentinel for read-repair failures. ErrRepair = errors.New("read repair error") // ErrRead is the canonical sentinel for replica read failures. ErrRead = errors.New("read error") ErrNoDiffFound = errors.New("no diff found") // ErrConflictExistOrDeleted is returned during read-repair when an object // exists on one replica but has been deleted on another. ErrConflictExistOrDeleted = errors.New("conflict: object has been deleted on another replica") // ErrConflictObjectChanged is returned when the source object changed // between the digest read and the repair write. ErrConflictObjectChanged = errors.New("source object changed during repair") )
Sentinel errors – use errors.Is / errors.As to inspect wrapped values.
Functions ¶
func NewNotEnoughReplicasError ¶
NewNotEnoughReplicasError wraps cause in an error that satisfies errors.Is(err, ErrReplicas). Use this form when only the underlying error is known (e.g. a routing-plan failure); for richer diagnostics from the coordinator use NewNotEnoughReplicasErrorWithCounts.
func NewNotEnoughReplicasErrorWithCounts ¶
NewNotEnoughReplicasErrorWithCounts is the rich form of NewNotEnoughReplicasError used by the coordinator when it knows how many replicas were required vs. succeeded.
func NewReadError ¶
NewReadError constructs an error that satisfies errors.Is(err, ErrRead) and wraps cause.
func NewRepairError ¶
NewRepairError constructs an error that satisfies errors.Is(err, ErrRepair) and wraps cause.
func StatusText ¶
func StatusText(code StatusCode) string
StatusText returns a text for the status code. It returns the empty string if the code is unknown.
Types ¶
type Error ¶
type Error struct {
Code StatusCode `json:"code"`
Msg string `json:"msg,omitempty"`
Err error `json:"-"`
}
Error reports an error that occurred during replication. It is used as a wire-level type and is intentionally JSON-serialisable.
func NewError ¶
func NewError(code StatusCode, msg string) *Error
NewError creates a new replication error with the given code and message.
func (*Error) Empty ¶
Empty reports whether e is semantically nil (no code, no message, no underlying error), which is equivalent to the absence of an error.
func (*Error) IsStatusCode ¶
func (e *Error) IsStatusCode(sc StatusCode) bool
IsStatusCode reports whether e carries the given status code.
type StatusCode ¶
type StatusCode int
StatusCode communicates the cause of failure during replication.
const ( StatusOK StatusCode = 0 StatusClassNotFound StatusCode = iota + 200 StatusShardNotFound StatusNotFound StatusAlreadyExisted StatusNotReady StatusConflict StatusCode = iota + 300 StatusPreconditionFailed StatusReadOnly StatusObjectNotFound )