grpc

package
v2.0.2 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2026 License: AGPL-3.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecodeErrorFromStatus

func DecodeErrorFromStatus(ctx context.Context, err error) error

DecodeErrorFromStatus extracts the EncodedError from gRPC status details (if present) and decodes it so errors.Is() works across the wire. Returns the decoded error, or the original status error if no encoded detail is found.

func MapToGRPC

func MapToGRPC(err error, defaultCode codes.Code) codes.Code

MapToGRPC returns the appropriate gRPC code for known sentinel errors. It tries PlatformMapper first, then each registered domain mapper. Use std errors.Is for matching. Returns defaultCode if no match.

func PrepareAndLogGRPCStatus

func PrepareAndLogGRPCStatus(err error, logger logging.Logger, span tracing.Span, defaultCode codes.Code, descriptionFmt string, descriptionArgs ...any) error

PrepareAndLogGRPCStatus derives the gRPC code via MapToGRPC, then logs, traces, and returns a status error. Use defaultCode as the fallback for unknown errors.

func RegisterGRPCErrorMapper

func RegisterGRPCErrorMapper(m GRPCErrorMapper)

RegisterGRPCErrorMapper registers a domain-specific error mapper. Domains call this from init() to contribute their error mappings.

func StreamErrorEncodingInterceptor

func StreamErrorEncodingInterceptor() grpc.StreamServerInterceptor

StreamErrorEncodingInterceptor returns a stream interceptor that encodes handler errors into gRPC status details for wire transmission.

func UnaryErrorEncodingInterceptor

func UnaryErrorEncodingInterceptor() grpc.UnaryServerInterceptor

UnaryErrorEncodingInterceptor returns a unary interceptor that encodes handler errors into gRPC status details for wire transmission. Handlers should return errors (optionally wrapped); the interceptor will derive the gRPC code via MapToGRPC and attach the encoded error to details.

Types

type GRPCErrorMapper

type GRPCErrorMapper interface {
	Map(err error) (code codes.Code, ok bool)
}

GRPCErrorMapper maps domain errors to gRPC codes. ok=false means no match.

var PlatformMapper GRPCErrorMapper = platformMapper{}

PlatformMapper maps platform-level errors to gRPC codes. It does not depend on any domain.

Jump to

Keyboard shortcuts

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