yarpcerrors

package
v1.13.1 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2017 License: MIT Imports: 4 Imported by: 207

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AbortedErrorf

func AbortedErrorf(format string, args ...interface{}) error

AbortedErrorf returns a new yarpc error with code CodeAborted.

func AlreadyExistsErrorf

func AlreadyExistsErrorf(format string, args ...interface{}) error

AlreadyExistsErrorf returns a new yarpc error with code CodeAlreadyExists.

func CancelledErrorf

func CancelledErrorf(format string, args ...interface{}) error

CancelledErrorf returns a new yarpc error with code CodeCancelled.

func DataLossErrorf

func DataLossErrorf(format string, args ...interface{}) error

DataLossErrorf returns a new yarpc error with code CodeDataLoss.

func DeadlineExceededErrorf

func DeadlineExceededErrorf(format string, args ...interface{}) error

DeadlineExceededErrorf returns a new yarpc error with code CodeDeadlineExceeded.

func ErrorMessage

func ErrorMessage(err error) string

ErrorMessage returns the message for the given error, or "" if the given error is not a YARPC error or the YARPC error had no message.

func ErrorName

func ErrorName(err error) string

ErrorName returns the name for the given error, or "" if the given error is not a YARPC error created with NamedErrorf that has a non-empty name.

func FailedPreconditionErrorf

func FailedPreconditionErrorf(format string, args ...interface{}) error

FailedPreconditionErrorf returns a new yarpc error with code CodeFailedPrecondition.

func FromHeaders

func FromHeaders(code Code, name string, message string) error

FromHeaders returns a new yarpc error from headers transmitted from the server side.

If the specified code is CodeOK, this will return nil. If the specified code is not CodeUnknown, this will not set the name field.

The name must only contain lowercase letters from a-z and dashes (-), and cannot start or end in a dash. If the name is something else, an error with code CodeInternal will be returned.

This function should not be used by server implementations, use the individual error constructors instead. This should only be used by transport implementations.

func InternalErrorf

func InternalErrorf(format string, args ...interface{}) error

InternalErrorf returns a new yarpc error with code CodeInternal.

func InvalidArgumentErrorf

func InvalidArgumentErrorf(format string, args ...interface{}) error

InvalidArgumentErrorf returns a new yarpc error with code CodeInvalidArgument.

func IsAborted

func IsAborted(err error) bool

IsAborted returns true if ErrorCode(err) == CodeAborted.

func IsAlreadyExists

func IsAlreadyExists(err error) bool

IsAlreadyExists returns true if ErrorCode(err) == CodeAlreadyExists.

func IsCancelled

func IsCancelled(err error) bool

IsCancelled returns true if ErrorCode(err) == CodeCancelled.

func IsDataLoss

func IsDataLoss(err error) bool

IsDataLoss returns true if ErrorCode(err) == CodeDataLoss.

func IsDeadlineExceeded

func IsDeadlineExceeded(err error) bool

IsDeadlineExceeded returns true if ErrorCode(err) == CodeDeadlineExceeded.

func IsFailedPrecondition

func IsFailedPrecondition(err error) bool

IsFailedPrecondition returns true if ErrorCode(err) == CodeFailedPrecondition.

func IsInternal

func IsInternal(err error) bool

IsInternal returns true if ErrorCode(err) == CodeInternal.

func IsInvalidArgument

func IsInvalidArgument(err error) bool

IsInvalidArgument returns true if ErrorCode(err) == CodeInvalidArgument.

func IsNotFound

func IsNotFound(err error) bool

IsNotFound returns true if ErrorCode(err) == CodeNotFound.

func IsOutOfRange

func IsOutOfRange(err error) bool

IsOutOfRange returns true if ErrorCode(err) == CodeOutOfRange.

func IsPermissionDenied

func IsPermissionDenied(err error) bool

IsPermissionDenied returns true if ErrorCode(err) == CodePermissionDenied.

func IsResourceExhausted

func IsResourceExhausted(err error) bool

IsResourceExhausted returns true if ErrorCode(err) == CodeResourceExhausted.

func IsUnauthenticated

func IsUnauthenticated(err error) bool

IsUnauthenticated returns true if ErrorCode(err) == CodeUnauthenticated.

func IsUnavailable

func IsUnavailable(err error) bool

IsUnavailable returns true if ErrorCode(err) == CodeUnavailable.

func IsUnimplemented

func IsUnimplemented(err error) bool

IsUnimplemented returns true if ErrorCode(err) == CodeUnimplemented.

func IsUnknown

func IsUnknown(err error) bool

IsUnknown returns true if ErrorCode(err) == CodeUnknown.

func IsYARPCError

func IsYARPCError(err error) bool

IsYARPCError is a convenience function that returns true if the given error is a non-nil YARPC error.

This is equivalent to yarpcerrors.ErrorCode(err) != yarpcerrors.CodeOK.

func NamedErrorf

func NamedErrorf(name string, format string, args ...interface{}) error

NamedErrorf returns a new yarpc error with code CodeUnknown and the given name.

This should be used for user-defined errors.

The name must only contain lowercase letters from a-z and dashes (-), and cannot start or end in a dash. If the name is something else, an error with code CodeInternal will be returned.

func NotFoundErrorf

func NotFoundErrorf(format string, args ...interface{}) error

NotFoundErrorf returns a new yarpc error with code CodeNotFound.

func OutOfRangeErrorf

func OutOfRangeErrorf(format string, args ...interface{}) error

OutOfRangeErrorf returns a new yarpc error with code CodeOutOfRange.

func PermissionDeniedErrorf

func PermissionDeniedErrorf(format string, args ...interface{}) error

PermissionDeniedErrorf returns a new yarpc error with code CodePermissionDenied.

func ResourceExhaustedErrorf

func ResourceExhaustedErrorf(format string, args ...interface{}) error

ResourceExhaustedErrorf returns a new yarpc error with code CodeResourceExhausted.

func UnauthenticatedErrorf

func UnauthenticatedErrorf(format string, args ...interface{}) error

UnauthenticatedErrorf returns a new yarpc error with code CodeUnauthenticated.

func UnavailableErrorf

func UnavailableErrorf(format string, args ...interface{}) error

UnavailableErrorf returns a new yarpc error with code CodeUnavailable.

func UnimplementedErrorf

func UnimplementedErrorf(format string, args ...interface{}) error

UnimplementedErrorf returns a new yarpc error with code CodeUnimplemented.

func UnknownErrorf

func UnknownErrorf(format string, args ...interface{}) error

UnknownErrorf returns a new yarpc error with code CodeUnknown.

Types

type Code

type Code int

Code represents the type of error for an RPC call.

Sometimes multiple error codes may apply. Services should return the most specific error code that applies. For example, prefer `OutOfRange` over `FailedPrecondition` if both codes apply. Similarly prefer `NotFound` or `AlreadyExists` over `FailedPrecondition`.

const (
	// CodeOK means no error; returned on success
	CodeOK Code = 0

	// CodeCancelled means the operation was cancelled, typically by the caller.
	CodeCancelled Code = 1

	// CodeUnknown means an unknown error. Errors raised by APIs
	// that do not return enough error information
	// may be converted to this error.
	CodeUnknown Code = 2

	// CodeInvalidArgument means the client specified an invalid argument.
	// Note that this differs from `FailedPrecondition`. `InvalidArgument`
	// indicates arguments that are problematic regardless of the state of
	// the system (e.g., a malformed file name).
	CodeInvalidArgument Code = 3

	// CodeDeadlineExceeded means the deadline expired before the operation could
	// complete. 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.
	CodeDeadlineExceeded Code = 4

	// CodeNotFound means some requested entity (e.g., file or directory) was not found.
	// For privacy reasons, this code *may* be returned when the client
	// does not have the access rights to the entity, though such usage is
	// discouraged.
	CodeNotFound Code = 5

	// CodeAlreadyExists means the entity that a client attempted to create
	// (e.g., file or directory) already exists.
	CodeAlreadyExists Code = 6

	// CodePermissionDenied means the caller does not have permission to execute
	// the specified operation. `PermissionDenied` must not be used for rejections
	// caused by exhausting some resource (use `ResourceExhausted`
	// instead for those errors). `PermissionDenied` must not be
	// used if the caller can not be identified (use `Unauthenticated`
	// instead for those errors).
	CodePermissionDenied Code = 7

	// CodeResourceExhausted means some resource has been exhausted, perhaps a per-user
	// quota, or perhaps the entire file system is out of space.
	CodeResourceExhausted Code = 8

	// CodeFailedPrecondition means the operation was rejected because the system is not
	// in a state required for the operation's execution. For example, the directory
	// to be deleted is non-empty, an rmdir operation is applied to
	// a non-directory, etc.
	//
	// Service implementors can use the following guidelines to decide
	// 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
	//      the files are deleted from the directory.
	CodeFailedPrecondition Code = 9

	// CodeAborted means the operation was aborted, typically due to a concurrency issue
	// such as a sequencer check failure or transaction abort.
	//
	// See the guidelines above for deciding between `FailedPrecondition`,
	// `Aborted`, and `Unavailable`.
	CodeAborted Code = 10

	// CodeOutOfRange means the 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.
	CodeOutOfRange Code = 11

	// CodeUnimplemented means the operation is not implemented or is not
	// supported/enabled in this service.
	CodeUnimplemented Code = 12

	// CodeInternal means an internal error. This means that some invariants expected
	// by the underlying system have been broken. This error code is reserved
	// for serious errors.
	CodeInternal Code = 13

	// CodeUnavailable means the service is currently unavailable. This is most likely a
	// transient condition, which can be corrected by retrying with a backoff.
	//
	// See the guidelines above for deciding between `FailedPrecondition`,
	// `Aborted`, and `Unavailable`.
	CodeUnavailable Code = 14

	// CodeDataLoss means unrecoverable data loss or corruption.
	CodeDataLoss Code = 15

	// CodeUnauthenticated means the request does not have valid authentication
	// credentials for the operation.
	CodeUnauthenticated Code = 16
)

func ErrorCode

func ErrorCode(err error) Code

ErrorCode returns the Code for the given error, or CodeOK if the given error is not a YARPC error.

func (Code) MarshalJSON

func (c Code) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler.

func (Code) MarshalText

func (c Code) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler.

func (Code) String

func (c Code) String() string

String returns the the string representation of the Code.

func (*Code) UnmarshalJSON

func (c *Code) UnmarshalJSON(text []byte) error

UnmarshalJSON implements json.Unmarshaler.

func (*Code) UnmarshalText

func (c *Code) UnmarshalText(text []byte) error

UnmarshalText implements encoding.TextUnmarshaler.

Jump to

Keyboard shortcuts

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