errors

package
v1.38.0-rc.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 27, 2026 License: BSD-3-Clause Imports: 3 Imported by: 0

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

View Source
const MsgCLevel = "cannot achieve consistency level"

MsgCLevel is the human-readable prefix used in consistency-level errors.

Variables

View Source
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

func NewNotEnoughReplicasError(cause error) error

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

func NewNotEnoughReplicasErrorWithCounts(required, got int, cause error) error

NewNotEnoughReplicasErrorWithCounts is the rich form of NewNotEnoughReplicasError used by the coordinator when it knows how many replicas were required vs. succeeded.

func NewReadError

func NewReadError(cause error) error

NewReadError constructs an error that satisfies errors.Is(err, ErrRead) and wraps cause.

func NewRepairError

func NewRepairError(cause error) error

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) Clone

func (e *Error) Clone() *Error

Clone returns a shallow copy of e.

func (*Error) Empty

func (e *Error) Empty() bool

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) Error

func (e *Error) Error() string

func (*Error) IsStatusCode

func (e *Error) IsStatusCode(sc StatusCode) bool

IsStatusCode reports whether e carries the given status code.

func (*Error) Timeout

func (e *Error) Timeout() bool

Timeout reports whether the underlying error is a timeout.

func (*Error) Unwrap

func (e *Error) Unwrap() error

Unwrap returns the underlying error so that errors.Is / errors.As can traverse the chain.

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
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL