errors

package
v0.4.9 Latest Latest
Warning

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

Go to latest
Published: Dec 31, 2025 License: MIT Imports: 16 Imported by: 1

Documentation

Index

Constants

View Source
const CHAINABLE_ERROR_TYPE_GOLANG = "errorString"
View Source
const CHAINABLE_ERROR_TYPE_STANDARD = _STANDARD_ERROR_TYPE
View Source
const GRPC_STATUS_MAX_CODE = 17

Variables

View Source
var (
	// optional int32 default_code = 51001;
	E_DefaultCode = &file_errors_proto_extTypes[0]
	// optional ellie.errors.ErrorStatus default_status = 51002;
	E_DefaultStatus = &file_errors_proto_extTypes[1]
)

Extension fields to descriptorpb.EnumOptions.

View Source
var (
	// optional int32 code = 52001;
	E_Code = &file_errors_proto_extTypes[2]
	// optional ellie.errors.ErrorStatus status = 52002;
	E_Status = &file_errors_proto_extTypes[3]
)

Extension fields to descriptorpb.EnumValueOptions.

View Source
var (
	ErrorStatus_name = map[int32]string{
		0:  "ERROR_STATUS_UNSPECIFIED",
		1:  "ERROR_STATUS_OK",
		2:  "ERROR_STATUS_CANCELED",
		3:  "ERROR_STATUS_UNKNOWN",
		4:  "ERROR_STATUS_INVALID_ARGUMENT",
		5:  "ERROR_STATUS_DEADLINE_EXCEEDED",
		6:  "ERROR_STATUS_NOT_FOUND",
		7:  "ERROR_STATUS_ALREADY_EXISTS",
		8:  "ERROR_STATUS_PERMISSION_DENIED",
		9:  "ERROR_STATUS_RESOURCE_EXHAUSTED",
		10: "ERROR_STATUS_FAILED_PRECONDITION",
		11: "ERROR_STATUS_ABORTED",
		12: "ERROR_STATUS_OUT_OF_RANGE",
		13: "ERROR_STATUS_UNIMPLEMENTED",
		14: "ERROR_STATUS_INTERNAL",
		15: "ERROR_STATUS_UNAVAILABLE",
		16: "ERROR_STATUS_DATA_LOSS",
		17: "ERROR_STATUS_UNAUTHENTICATED",
	}
	ErrorStatus_value = map[string]int32{
		"ERROR_STATUS_UNSPECIFIED":         0,
		"ERROR_STATUS_OK":                  1,
		"ERROR_STATUS_CANCELED":            2,
		"ERROR_STATUS_UNKNOWN":             3,
		"ERROR_STATUS_INVALID_ARGUMENT":    4,
		"ERROR_STATUS_DEADLINE_EXCEEDED":   5,
		"ERROR_STATUS_NOT_FOUND":           6,
		"ERROR_STATUS_ALREADY_EXISTS":      7,
		"ERROR_STATUS_PERMISSION_DENIED":   8,
		"ERROR_STATUS_RESOURCE_EXHAUSTED":  9,
		"ERROR_STATUS_FAILED_PRECONDITION": 10,
		"ERROR_STATUS_ABORTED":             11,
		"ERROR_STATUS_OUT_OF_RANGE":        12,
		"ERROR_STATUS_UNIMPLEMENTED":       13,
		"ERROR_STATUS_INTERNAL":            14,
		"ERROR_STATUS_UNAVAILABLE":         15,
		"ERROR_STATUS_DATA_LOSS":           16,
		"ERROR_STATUS_UNAUTHENTICATED":     17,
	}
)

Enum value maps for ErrorStatus.

View Source
var File_ellie_errors_status_proto protoreflect.FileDescriptor
View Source
var File_errors_proto protoreflect.FileDescriptor

Functions

func As

func As(err error, target any) bool

As finds the first error in err's tree that matches target, and if one is found, sets target to that error value and returns true. Otherwise, it returns false.

The tree consists of err itself, followed by the errors obtained by repeatedly calling its Unwrap() error or Unwrap() []error method. When err wraps multiple errors, As examines err followed by a depth-first traversal of its children.

An error matches target if the error's concrete value is assignable to the value pointed to by target, or if the error has a method As(any) bool such that As(target) returns true. In the latter case, the As method is responsible for setting target.

An error type might provide an As method so it can be treated as if it were a different error type.

As panics if target is not a non-nil pointer to either a type that implements error, or to any interface type.

func Errorf

func Errorf(code int, reason, format string, a ...any) error

func Is

func Is(err, target error) bool

Is reports whether any error in err's tree matches target.

The tree consists of err itself, followed by the errors obtained by repeatedly calling its Unwrap() error or Unwrap() []error method. When err wraps multiple errors, Is examines err followed by a depth-first traversal of its children.

An error is considered to match a target if it is equal to that target or if it implements a method Is(error) bool such that Is(target) returns true.

An error type might provide an Is method so it can be treated as equivalent to an existing error. For example, if MyError defines

func (m MyError) Is(target error) bool { return target == fs.ErrExist }

then Is(MyError{}, fs.ErrExist) returns true. See syscall.Errno.Is for an example in the standard library. An Is method should only shallowly compare err and the target and not call Unwrap on either.

func New

func New(code int, reason, message string) error

func Newf

func Newf(code int, reason, format string, a ...any) error

func PackErrorChain added in v0.4.6

func PackErrorChain(code codes.Code, err error) error

func RegisterChainableErrorType added in v0.4.0

func RegisterChainableErrorType(ty string, fn func(string, []byte) error) error

func StatusCodeFromError added in v0.4.5

func StatusCodeFromError(err error) codes.Code

func StatusPtrFromInt added in v0.4.3

func StatusPtrFromInt(code int) *codes.Code

func UnpackErrorChain added in v0.4.6

func UnpackErrorChain(err error) error

func Unwrap

func Unwrap(err error) error

Unwrap returns the result of calling the Unwrap method on err, if err's type contains an Unwrap method returning error. Otherwise, Unwrap returns nil.

Unwrap only calls a method of the form "Unwrap() error". In particular Unwrap does not unwrap errors returned by [Join].

func UnwrapGRPCResponse added in v0.4.1

func UnwrapGRPCResponse[T any](data T, err error) (T, error)

func WrapGRPCResponse added in v0.4.7

func WrapGRPCResponse[T any](data T, err error) (T, error)

Types

type AdvancedError added in v0.4.1

type AdvancedError interface {
	Unwrap() error
	Is(error) bool

	// getters
	Status() *codes.Code
	Code() int32
	Reason() string
	Message() string
	Metadata() map[string]string
	Cause() error

	// setters
	WithStatus(codes.Code) AdvancedError
	WithCode(int32) AdvancedError
	WithReason(string) AdvancedError
	WithMessage(string, ...any) AdvancedError
	WithMetadata(map[string]string) AdvancedError
	WithCause(error) AdvancedError

	Chainable
}

type Chainable added in v0.4.0

type Chainable interface {
	error

	Type() string
	Wrap(error) error
	Marshal() ([]byte, error)
}

type ErrorChain added in v0.4.0

type ErrorChain struct {
	Root *ErrorChainNode `protobuf:"bytes,1,opt,name=root,proto3" json:"root,omitempty"`
	// contains filtered or unexported fields
}

func (*ErrorChain) Descriptor deprecated added in v0.4.0

func (*ErrorChain) Descriptor() ([]byte, []int)

Deprecated: Use ErrorChain.ProtoReflect.Descriptor instead.

func (*ErrorChain) GetRoot added in v0.4.0

func (x *ErrorChain) GetRoot() *ErrorChainNode

func (*ErrorChain) ProtoMessage added in v0.4.0

func (*ErrorChain) ProtoMessage()

func (*ErrorChain) ProtoReflect added in v0.4.0

func (x *ErrorChain) ProtoReflect() protoreflect.Message

func (*ErrorChain) Reset added in v0.4.0

func (x *ErrorChain) Reset()

func (*ErrorChain) String added in v0.4.0

func (x *ErrorChain) String() string

type ErrorChainNode added in v0.4.0

type ErrorChainNode struct {
	Type    string          `protobuf:"bytes,1,opt,name=type,proto3" json:"type,omitempty"`
	Message string          `protobuf:"bytes,2,opt,name=message,proto3" json:"message,omitempty"`
	Data    []byte          `protobuf:"bytes,3,opt,name=data,proto3" json:"data,omitempty"`
	Wrapped *ErrorChainNode `protobuf:"bytes,4,opt,name=wrapped,proto3" json:"wrapped,omitempty"`
	// contains filtered or unexported fields
}

func (*ErrorChainNode) Descriptor deprecated added in v0.4.0

func (*ErrorChainNode) Descriptor() ([]byte, []int)

Deprecated: Use ErrorChainNode.ProtoReflect.Descriptor instead.

func (*ErrorChainNode) GetData added in v0.4.0

func (x *ErrorChainNode) GetData() []byte

func (*ErrorChainNode) GetMessage added in v0.4.0

func (x *ErrorChainNode) GetMessage() string

func (*ErrorChainNode) GetType added in v0.4.0

func (x *ErrorChainNode) GetType() string

func (*ErrorChainNode) GetWrapped added in v0.4.0

func (x *ErrorChainNode) GetWrapped() *ErrorChainNode

func (*ErrorChainNode) ProtoMessage added in v0.4.0

func (*ErrorChainNode) ProtoMessage()

func (*ErrorChainNode) ProtoReflect added in v0.4.0

func (x *ErrorChainNode) ProtoReflect() protoreflect.Message

func (*ErrorChainNode) Reset added in v0.4.0

func (x *ErrorChainNode) Reset()

func (*ErrorChainNode) String added in v0.4.0

func (x *ErrorChainNode) String() string

type ErrorCore added in v0.4.2

type ErrorCore struct {
	Code     int32             `protobuf:"varint,2,opt,name=code,proto3" json:"code,omitempty"`
	Reason   string            `protobuf:"bytes,3,opt,name=reason,proto3" json:"reason,omitempty"`
	Message  string            `protobuf:"bytes,4,opt,name=message,proto3" json:"message,omitempty"`
	Metadata map[string]string `` /* 143-byte string literal not displayed */
	// grpc codes.Code(status - 1)
	Status *int32 `protobuf:"varint,1,opt,name=status,proto3,oneof" json:"status,omitempty"`
	// contains filtered or unexported fields
}

func (*ErrorCore) Descriptor deprecated added in v0.4.2

func (*ErrorCore) Descriptor() ([]byte, []int)

Deprecated: Use ErrorCore.ProtoReflect.Descriptor instead.

func (*ErrorCore) GetCode added in v0.4.2

func (x *ErrorCore) GetCode() int32

func (*ErrorCore) GetMessage added in v0.4.2

func (x *ErrorCore) GetMessage() string

func (*ErrorCore) GetMetadata added in v0.4.2

func (x *ErrorCore) GetMetadata() map[string]string

func (*ErrorCore) GetReason added in v0.4.2

func (x *ErrorCore) GetReason() string

func (*ErrorCore) GetStatus added in v0.4.2

func (x *ErrorCore) GetStatus() int32

func (*ErrorCore) ProtoMessage added in v0.4.2

func (*ErrorCore) ProtoMessage()

func (*ErrorCore) ProtoReflect added in v0.4.2

func (x *ErrorCore) ProtoReflect() protoreflect.Message

func (*ErrorCore) Reset added in v0.4.2

func (x *ErrorCore) Reset()

func (*ErrorCore) String added in v0.4.2

func (x *ErrorCore) String() string

type ErrorStatus added in v0.4.1

type ErrorStatus int32
const (
	// fallback to UNKNOWN
	ErrorStatus_ERROR_STATUS_UNSPECIFIED ErrorStatus = 0
	// OK is returned on success.
	ErrorStatus_ERROR_STATUS_OK ErrorStatus = 1
	// Canceled indicates the operation was canceled (typically by the caller).
	//
	// The gRPC framework will generate this error code when cancellation
	// is requested.
	ErrorStatus_ERROR_STATUS_CANCELED ErrorStatus = 2
	// Unknown error. An example of where this error may be returned is
	// if a Status value received from another address space belongs to
	// an error-space that is not known in this address space. Also
	// errors raised by APIs that do not return enough error information
	// may be converted to this error.
	//
	// The gRPC framework will generate this error code in the above two
	// mentioned cases.
	ErrorStatus_ERROR_STATUS_UNKNOWN ErrorStatus = 3
	// InvalidArgument indicates client specified an invalid argument.
	// Note that this differs from FailedPrecondition. It indicates arguments
	// that are problematic regardless of the state of the system
	// (e.g., a malformed file name).
	//
	// This error code will not be generated by the gRPC framework.
	ErrorStatus_ERROR_STATUS_INVALID_ARGUMENT ErrorStatus = 4
	// DeadlineExceeded means operation expired before completion.
	// For operations that change the state of the system, this error may be
	// returned even if the operation has completed successfully. For
	// example, a successful response from a server could have been delayed
	// long enough for the deadline to expire.
	//
	// The gRPC framework will generate this error code when the deadline is
	// exceeded.
	ErrorStatus_ERROR_STATUS_DEADLINE_EXCEEDED ErrorStatus = 5
	// NotFound means some requested entity (e.g., file or directory) was
	// not found.
	//
	// This error code will not be generated by the gRPC framework.
	ErrorStatus_ERROR_STATUS_NOT_FOUND ErrorStatus = 6
	// AlreadyExists means an attempt to create an entity failed because one
	// already exists.
	//
	// This error code will not be generated by the gRPC framework.
	ErrorStatus_ERROR_STATUS_ALREADY_EXISTS ErrorStatus = 7
	// PermissionDenied indicates the caller does not have permission to
	// execute the specified operation. It must not be used for rejections
	// caused by exhausting some resource (use ResourceExhausted
	// instead for those errors). It must not be
	// used if the caller cannot be identified (use Unauthenticated
	// instead for those errors).
	//
	// This error code will not be generated by the gRPC core framework,
	// but expect authentication middleware to use it.
	ErrorStatus_ERROR_STATUS_PERMISSION_DENIED ErrorStatus = 8
	// ResourceExhausted indicates some resource has been exhausted, perhaps
	// a per-user quota, or perhaps the entire file system is out of space.
	//
	// This error code will be generated by the gRPC framework in
	// out-of-memory and server overload situations, or when a message is
	// larger than the configured maximum size.
	ErrorStatus_ERROR_STATUS_RESOURCE_EXHAUSTED ErrorStatus = 9
	// FailedPrecondition indicates operation was rejected because the
	// system is not in a state required for the operation's execution.
	// For example, directory to be deleted may be non-empty, an rmdir
	// operation is applied to a non-directory, etc.
	//
	// A litmus test that may help a service implementor in deciding
	// between FailedPrecondition, Aborted, and Unavailable:
	//
	//	(a) Use Unavailable if the client can retry just the failing call.
	//	(b) Use Aborted if the client should retry at a higher-level
	//	    (e.g., restarting a read-modify-write sequence).
	//	(c) Use FailedPrecondition if the client should not retry until
	//	    the system state has been explicitly fixed. E.g., if an "rmdir"
	//	    fails because the directory is non-empty, FailedPrecondition
	//	    should be returned since the client should not retry unless
	//	    they have first fixed up the directory by deleting files from it.
	//	(d) Use FailedPrecondition if the client performs conditional
	//	    REST Get/Update/Delete on a resource and the resource on the
	//	    server does not match the condition. E.g., conflicting
	//	    read-modify-write on the same resource.
	//
	// This error code will not be generated by the gRPC framework.
	ErrorStatus_ERROR_STATUS_FAILED_PRECONDITION ErrorStatus = 10
	// Aborted indicates the operation was aborted, typically due to a
	// concurrency issue like sequencer check failures, transaction aborts,
	// etc.
	//
	// See litmus test above for deciding between FailedPrecondition,
	// Aborted, and Unavailable.
	//
	// This error code will not be generated by the gRPC framework.
	ErrorStatus_ERROR_STATUS_ABORTED ErrorStatus = 11
	// OutOfRange means operation was attempted past the valid range.
	// E.g., seeking or reading past end of file.
	//
	// Unlike InvalidArgument, this error indicates a problem that may
	// be fixed if the system state changes. For example, a 32-bit file
	// system will generate InvalidArgument if asked to read at an
	// offset that is not in the range [0,2^32-1], but it will generate
	// OutOfRange if asked to read from an offset past the current
	// file size.
	//
	// There is a fair bit of overlap between FailedPrecondition and
	// OutOfRange. We recommend using OutOfRange (the more specific
	// error) when it applies so that callers who are iterating through
	// a space can easily look for an OutOfRange error to detect when
	// they are done.
	//
	// This error code will not be generated by the gRPC framework.
	ErrorStatus_ERROR_STATUS_OUT_OF_RANGE ErrorStatus = 12
	// Unimplemented indicates operation is not implemented or not
	// supported/enabled in this service.
	//
	// This error code will be generated by the gRPC framework. Most
	// commonly, you will see this error code when a method implementation
	// is missing on the server. It can also be generated for unknown
	// compression algorithms or a disagreement as to whether an RPC should
	// be streaming.
	ErrorStatus_ERROR_STATUS_UNIMPLEMENTED ErrorStatus = 13
	// Internal errors. Means some invariants expected by underlying
	// system has been broken. If you see one of these errors,
	// something is very broken.
	//
	// This error code will be generated by the gRPC framework in several
	// internal error conditions.
	ErrorStatus_ERROR_STATUS_INTERNAL ErrorStatus = 14
	// Unavailable indicates the service is currently unavailable.
	// This is a most likely a transient condition and may be corrected
	// by retrying with a backoff. Note that it is not always safe to retry
	// non-idempotent operations.
	//
	// See litmus test above for deciding between FailedPrecondition,
	// Aborted, and Unavailable.
	//
	// This error code will be generated by the gRPC framework during
	// abrupt shutdown of a server process or network connection.
	ErrorStatus_ERROR_STATUS_UNAVAILABLE ErrorStatus = 15
	// DataLoss indicates unrecoverable data loss or corruption.
	//
	// This error code will not be generated by the gRPC framework.
	ErrorStatus_ERROR_STATUS_DATA_LOSS ErrorStatus = 16
	// Unauthenticated indicates the request does not have valid
	// authentication credentials for the operation.
	//
	// The gRPC framework will generate this error code when the
	// authentication metadata is invalid or a Credentials callback fails,
	// but also expect authentication middleware to generate it.
	ErrorStatus_ERROR_STATUS_UNAUTHENTICATED ErrorStatus = 17
)

func (ErrorStatus) Descriptor added in v0.4.1

func (ErrorStatus) Enum added in v0.4.2

func (x ErrorStatus) Enum() *ErrorStatus

func (ErrorStatus) EnumDescriptor deprecated added in v0.4.2

func (ErrorStatus) EnumDescriptor() ([]byte, []int)

Deprecated: Use ErrorStatus.Descriptor instead.

func (ErrorStatus) Number added in v0.4.2

func (x ErrorStatus) Number() protoreflect.EnumNumber

func (ErrorStatus) String added in v0.4.1

func (x ErrorStatus) String() string

func (ErrorStatus) Type added in v0.4.2

type StandardError added in v0.4.1

type StandardError struct {
	// contains filtered or unexported fields
}

func NewStandardError added in v0.4.1

func NewStandardError(status *codes.Code, code int, reason, message string) *StandardError

func NewStandardErrorFromError added in v0.4.1

func NewStandardErrorFromError(err error) *StandardError

func NewStandardErrorf added in v0.4.1

func NewStandardErrorf(status *codes.Code, code int, reason, format string, a ...any) *StandardError

func (*StandardError) Cause added in v0.4.1

func (se *StandardError) Cause() error

func (*StandardError) Clone added in v0.4.1

func (se *StandardError) Clone() *StandardError

func (*StandardError) Code added in v0.4.1

func (se *StandardError) Code() int32

func (*StandardError) Error added in v0.4.1

func (se *StandardError) Error() string

func (*StandardError) Is added in v0.4.1

func (se *StandardError) Is(target error) bool

func (*StandardError) MapError added in v0.4.3

func (se *StandardError) MapError() map[string]any

func (*StandardError) Marshal added in v0.4.1

func (se *StandardError) Marshal() ([]byte, error)

func (*StandardError) Message added in v0.4.1

func (se *StandardError) Message() string

func (*StandardError) Metadata added in v0.4.1

func (se *StandardError) Metadata() map[string]string

func (*StandardError) Reason added in v0.4.1

func (se *StandardError) Reason() string

func (*StandardError) Status added in v0.4.1

func (se *StandardError) Status() *codes.Code

func (*StandardError) Type added in v0.4.1

func (se *StandardError) Type() string

func (*StandardError) Unwrap added in v0.4.1

func (se *StandardError) Unwrap() error

func (*StandardError) WithCause added in v0.4.1

func (se *StandardError) WithCause(cause error) AdvancedError

func (*StandardError) WithCode added in v0.4.1

func (se *StandardError) WithCode(code int32) AdvancedError

func (*StandardError) WithMessage added in v0.4.1

func (se *StandardError) WithMessage(format string, a ...any) AdvancedError

func (*StandardError) WithMetadata added in v0.4.1

func (se *StandardError) WithMetadata(metadata map[string]string) AdvancedError

func (*StandardError) WithReason added in v0.4.1

func (se *StandardError) WithReason(reason string) AdvancedError

func (*StandardError) WithStatus added in v0.4.1

func (se *StandardError) WithStatus(status codes.Code) AdvancedError

func (*StandardError) Wrap added in v0.4.1

func (se *StandardError) Wrap(err error) error

Jump to

Keyboard shortcuts

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