status

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2021 License: MIT Imports: 7 Imported by: 1

Documentation

Overview

Package status provide wrapper of package status, codes of grpc-go and some utilities for working with status, errors.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Aborted

func Aborted(fmt string, args ...interface{}) error

Aborted indicates the operation was aborted, typically due to a concurrency issue like sequencer check failures, transaction aborts, etc.

func AlreadyExists

func AlreadyExists(fmt string, args ...interface{}) error

AlreadyExists means an attempt to create an entity failed because one already exists.

func Canceled

func Canceled(fmt string, args ...interface{}) error

Canceled indicates the operation was canceled (typically by the caller).

func DataLoss

func DataLoss(fmt string, args ...interface{}) error

DataLoss indicates unrecoverable data loss or corruption.

func DeadlineExceeded

func DeadlineExceeded(fmt string, args ...interface{}) error

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.

func Error

func Error(code Code, fmt string, args ...interface{}) error

Error return new error.

func FailedPrecondition

func FailedPrecondition(fmt string, args ...interface{}) error

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.

func HTTPStatusFromCode

func HTTPStatusFromCode(code Code) int

HTTPStatusFromCode converts a gRPC error code into the corresponding HTTP response status. See: https://github.com/googleapis/googleapis/blob/master/google/rpc/code.proto

func Internal

func Internal(fmt string, args ...interface{}) error

Internal errors. Means some invariants expected by underlying system has been broken. If you see one of these errors, something is very broken.

func InvalidArgument

func InvalidArgument(fmt string, args ...interface{}) error

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

func Is

func Is(err error, code Code) bool

Is check whether the given error has same code with the given code.

func IsAborted

func IsAborted(err error) bool

IsAborted check whether the given error is an Aborted error.

func IsAlreadyExists

func IsAlreadyExists(err error) bool

IsAlreadyExists check whether the given error is an AlreadyExists error.

func IsCanceled

func IsCanceled(err error) bool

IsCanceled check whether the error is a Canceled error.

func IsDataLoss

func IsDataLoss(err error) bool

IsDataLoss check whether the given error is a DataLoss error.

func IsDeadlineExceeded

func IsDeadlineExceeded(err error) bool

IsDeadlineExceeded check whether the given error is a DeadlineExceeded error.

func IsFailedPrecondition

func IsFailedPrecondition(err error) bool

IsFailedPrecondition check whether the given error is a FailedPrecondition error.

func IsInternal

func IsInternal(err error) bool

IsInternal check whether the given error is an Internal error.

func IsInvalidArgument

func IsInvalidArgument(err error) bool

IsInvalidArgument check whether the given error is an InvalidArgument.

func IsNotFound

func IsNotFound(err error) bool

IsNotFound check whether the given error is a NotFound error.

func IsOK

func IsOK(err error) bool

IsOK check whether the given error is actually OK message.

func IsOutOfRange

func IsOutOfRange(err error) bool

IsOutOfRange check whether the given error is an OutOfRange error.

func IsPermissionDenied

func IsPermissionDenied(err error) bool

IsPermissionDenied check whether the given error is a PermissionDenied error.

func IsResourceExhausted

func IsResourceExhausted(err error) bool

IsResourceExhausted check whether the given error is a ResourceExhausted error.

func IsUnauthenticated

func IsUnauthenticated(err error) bool

IsUnauthenticated check whether the given error is an Unauthenticated error.

func IsUnavailable

func IsUnavailable(err error) bool

IsUnavailable check whether the given error is an Unavailable error.

func IsUnimplemented

func IsUnimplemented(err error) bool

IsUnimplemented check whether the given error is an Unimplemented error.

func IsUnknown

func IsUnknown(err error) bool

IsUnknown check whether the given error is Unknown error.

func JSON

func JSON(v interface{}) []byte

JSON return JSON encoded of the given error or status.

func NotFound

func NotFound(fmt string, args ...interface{}) error

NotFound means some requested entity (e.g., file or directory) was not found.

func OutOfRange

func OutOfRange(fmt string, args ...interface{}) error

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.

func PermissionDenied

func PermissionDenied(fmt string, args ...interface{}) error

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

func ResourceExhausted

func ResourceExhausted(fmt string, args ...interface{}) error

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.

func Unauthenticated

func Unauthenticated(fmt string, args ...interface{}) error

Unauthenticated indicates the request does not have valid authentication credentials for the operation.

func Unavailable

func Unavailable(fmt string, args ...interface{}) error

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.

func Unimplemented

func Unimplemented(fmt string, args ...interface{}) error

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.

func Unknown

func Unknown(fmt string, args ...interface{}) error

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.

Types

type Code

type Code = codes.Code

Code is an alias of grpc codes.Code.

type Status

type Status = status.Status

Status is an alias of grpc status.Status.

func Convert

func Convert(err error) *Status

Convert is a convenience function which removes the need to handle the boolean return value from FromError.

func FromError

func FromError(err error) (s *Status, ok bool)

FromError returns a Status representing err if it was produced from this package or has a method `GRPCStatus() *Status`. Otherwise, ok is false and a Status is returned with codes.Unknown and the original error message.

func New

func New(code Code, fmt string, args ...interface{}) *Status

New return new status.

func OK

func OK(fmt string, args ...interface{}) *Status

OK is returned on success.

func Parse

func Parse(data []byte) (*Status, error)

Parse try to parse the given data to a Status.

Jump to

Keyboard shortcuts

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