gerr

package module
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DebugInfo

func DebugInfo(stackEntries []string, detail string) *errdetails.DebugInfo

DebugInfo creates a DebugInfo detail.

func FromStatus

func FromStatus(st *status.Status) *errx.Error

FromStatus converts a *status.Status to an *errx.Error. Returns nil if the status code is OK. Any gRPC status details are restored via errx.WithDetails.

func LocalizedMessage

func LocalizedMessage(locale, message string) *errdetails.LocalizedMessage

LocalizedMessage creates a LocalizedMessage detail.

func NewQuotaViolation

func NewQuotaViolation(subject, description string) *errdetails.QuotaFailure_Violation

NewQuotaViolation creates a single QuotaFailure_Violation.

func QuotaFailure

func QuotaFailure(violations ...*errdetails.QuotaFailure_Violation) *errdetails.QuotaFailure

QuotaFailure creates a QuotaFailure with the given violations.

func RegisterCode

func RegisterCode(c errx.Code, gc codes.Code)

RegisterCode registers a custom mapping between an errx.Code and a gRPC codes.Code. Both forward (errx → gRPC) and reverse (gRPC → errx) mappings are registered. Must be called at program initialization (e.g. in init()), before serving requests.

func RetryInfo

func RetryInfo(retryDelay time.Duration) *errdetails.RetryInfo

RetryInfo creates a RetryInfo detail with the given retry delay.

func StreamServerInterceptor

func StreamServerInterceptor(opts ...InterceptorOption) grpc.StreamServerInterceptor

StreamServerInterceptor returns a gRPC stream server interceptor that converts returned errors to gRPC status errors using ToStatus. If the error implements errx.Localizable, a LocalizedMessage detail is automatically appended.

func ToErrxCode

func ToErrxCode(c codes.Code) errx.Code

ToErrxCode maps a gRPC codes.Code to an errx.Code. codes.OK maps to the zero value ("").

func ToGRPCCode

func ToGRPCCode(c errx.Code) codes.Code

ToGRPCCode maps an errx.Code to a gRPC codes.Code. Unknown or user-defined codes map to codes.Unknown.

func ToStatus

func ToStatus(err error) *status.Status

ToStatus converts an error to a *status.Status. If the error carries an errx.Code, it is mapped to a gRPC code. The error message is used as the status message. Any detail objects (proto.Message) attached via errx.WithDetails are included as gRPC status details. Non-proto.Message details are ignored.

func UnaryServerInterceptor

func UnaryServerInterceptor(opts ...InterceptorOption) grpc.UnaryServerInterceptor

UnaryServerInterceptor returns a gRPC unary server interceptor that converts returned errors to gRPC status errors using ToStatus. If the error implements errx.Localizable, a LocalizedMessage detail is automatically appended.

Types

type InterceptorOption

type InterceptorOption func(*interceptorConfig)

InterceptorOption configures the gRPC server interceptors.

func WithDefaultLocale added in v0.0.3

func WithDefaultLocale(tag language.Tag) InterceptorOption

WithDefaultLocale sets a fallback locale used when the locale function returns an empty string (e.g. no accept-language metadata).

func WithLocaleFunc

func WithLocaleFunc(f func(context.Context) string) InterceptorOption

WithLocaleFunc sets a custom function to extract locale from context. The default parses the "accept-language" gRPC metadata value and returns the highest-priority language tag as a BCP 47 string.

Jump to

Keyboard shortcuts

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