errcode

package
v2.0.0-alpha.16 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2025 License: MIT Imports: 21 Imported by: 0

Documentation

Overview

Package errcode provides error code handling with gRPC compatibility.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CloneAndCheck

func CloneAndCheck(code *errorpb.ErrCode) *errorpb.ErrCode

CloneAndCheck clones and validates an error code.

func ConvertErr2Status

func ConvertErr2Status(errCode *errorpb.ErrCode) *status.Status

ConvertErr2Status converts an error code to a gRPC status. Internal conversion, so that when err=nil, OK information is included in monitoring data.

func Err2GrpcCode

func Err2GrpcCode(err error) codes.Code

Err2GrpcCode converts a standard Go error into its canonical code. Note that this is only used to translate the error returned by the server applications.

func GetErrCodes

func GetErrCodes() []*errorpb.ErrCode

func GrpcCodeToHTTP

func GrpcCodeToHTTP(code codes.Code) int

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

func Http2GrpcCode

func Http2GrpcCode(code int32) codes.Code

Http2GrpcCode converts an HTTP status code to a gRPC code.

func IsGrpcAcceptable

func IsGrpcAcceptable(err error) bool

IsGrpcAcceptable checks if a gRPC error is acceptable for retry.

func MustProtoToAny

func MustProtoToAny(p proto.Message) *anypb.Any

func MustStructToAny

func MustStructToAny(p map[string]any) *anypb.Any

func NewCodeErr

func NewCodeErr(code *errorpb.ErrCode, details ...proto.Message) error

func NewCodeErrWithMap

func NewCodeErrWithMap(code *errorpb.ErrCode, details ...map[string]any) error

func NewCodeErrWithMsg

func NewCodeErrWithMsg(code *errorpb.ErrCode, msg string, details ...proto.Message) error

func ParseErrToPb

func ParseErrToPb(err error) proto.Message

func ParseError

func ParseError(err error) *errorpb.ErrCode

ParseError tries to convert an error to *Error. It supports wrapped errors.

func RegisterErrCodes

func RegisterErrCodes(code *errorpb.ErrCode) error

func WrapCode

func WrapCode(err error, code *errorpb.ErrCode) error

Types

type ErrCode

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

ErrCode represents an error with code information.

func (*ErrCode) As

func (t *ErrCode) As(err any) bool

func (*ErrCode) Error

func (t *ErrCode) Error() string

func (*ErrCode) Format

func (t *ErrCode) Format(f fmt.State, verb rune)

func (*ErrCode) ID

func (t *ErrCode) ID() string

func (*ErrCode) Is

func (t *ErrCode) Is(err error) bool

func (*ErrCode) MarshalJSON

func (t *ErrCode) MarshalJSON() ([]byte, error)

func (*ErrCode) Proto

func (t *ErrCode) Proto() proto.Message

func (*ErrCode) String

func (t *ErrCode) String() string

func (*ErrCode) Unwrap

func (t *ErrCode) Unwrap() error

type ErrorProto

type ErrorProto interface {
	error
	Proto() proto.Message
}

ErrorProto is an interface for errors that can be converted to protobuf messages.

type GRPCStatus

type GRPCStatus interface {
	GRPCStatus() *status.Status
}

GRPCStatus is an interface for errors that have gRPC status.

Jump to

Keyboard shortcuts

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