errors

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2023 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const (
	OK = iota
	Canceled
	Unknown
	InvalidArgument
	DeadlineExceeded
	NotFound
	AlreadyExists
	PermissionDenied
	ResourceExhausted
	FailedPrecondition
	Aborted
	OutOfRange
	Unimplemented
	Internal
	Unavailable
	DataLoss
	Unauthenticated
)

Variables

View Source
var (
	SuccessReason  = "SUCCESS"
	SuccessMessage = "success"
	UnknownReason  = "UNKNOWN"
	UnknownMessage = "unknown"
)

Functions

This section is empty.

Types

type Code

type Code uint32

Code is the error code.

func (Code) String

func (c Code) String() string

String returns the string representation of the status.

type Error

type Error struct {
	*Status
}

Error is a micro error.

func New

func New(c Code, reason, msg string, kvs ...string) *Error

New returns an error with the specified code, reason, message and metadata.

func Newf

func Newf(c Code, reason, format string, a ...interface{}) *Error

Newf returns an error with the specified code, reason and message.

func UnknownError

func UnknownError(err error) *Error

UnknownError returns an error with unknown status.

func (*Error) Error

func (e *Error) Error() string

Error returns the error string.

func (*Error) Is

func (e *Error) Is(err error) bool

Is returns true if the error is of the specified type.

func (*Error) WithMetadata

func (e *Error) WithMetadata(md map[string]string) *Error

WithMetadata returns an error with metadata.

type Status

type Status struct {
	Code     Code
	Reason   string
	Message  string
	Metadata map[string]string
}

Status is a micro status.

func FromError

func FromError(err error) *Status

FromError returns a status from an error.

func SuccessStatus

func SuccessStatus() *Status

SuccessStatus returns a success status.

func UnknownStatus

func UnknownStatus(err error) *Status

UnknownStatus returns an unknown status.

func (*Status) Err

func (s *Status) Err() error

Err returns the error.

Jump to

Keyboard shortcuts

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