Documentation

Overview

    Package grpcutil is a utility package to supplement Google's gRPC package, "google.golang.org/grpc".

    Index

    Constants

    This section is empty.

    Variables

    View Source
    var (
    	// Errf falls through to grpc.Errorf, with the notable exception that it isn't
    	// named "Errorf" and, consequently, won't trigger "go vet" misuse errors.
    	Errf = grpc.Errorf
    
    	// OK is an empty grpc.OK status error.
    	OK = Errf(codes.OK, "")
    
    	// Canceled is an empty grpc.Canceled error.
    	Canceled = Errf(codes.Canceled, "")
    
    	// Unknown is an empty grpc.Unknown error.
    	Unknown = Errf(codes.Unknown, "")
    
    	// InvalidArgument is an empty grpc.InvalidArgument error.
    	InvalidArgument = Errf(codes.InvalidArgument, "")
    
    	// DeadlineExceeded is an empty grpc.DeadlineExceeded error.
    	DeadlineExceeded = Errf(codes.DeadlineExceeded, "")
    
    	// NotFound is an empty grpc.NotFound error.
    	NotFound = Errf(codes.NotFound, "")
    
    	// AlreadyExists is an empty grpc.AlreadyExists error.
    	AlreadyExists = Errf(codes.AlreadyExists, "")
    
    	// PermissionDenied is an empty grpc.PermissionDenied error.
    	PermissionDenied = Errf(codes.PermissionDenied, "")
    
    	// Unauthenticated is an empty grpc.Unauthenticated error.
    	Unauthenticated = Errf(codes.Unauthenticated, "")
    
    	// ResourceExhausted is an empty grpc.ResourceExhausted error.
    	ResourceExhausted = Errf(codes.ResourceExhausted, "")
    
    	// FailedPrecondition is an empty grpc.FailedPrecondition error.
    	FailedPrecondition = Errf(codes.FailedPrecondition, "")
    
    	// Aborted is an empty grpc.Aborted error.
    	Aborted = Errf(codes.Aborted, "")
    
    	// OutOfRange is an empty grpc.OutOfRange error.
    	OutOfRange = Errf(codes.OutOfRange, "")
    
    	// Unimplemented is an empty grpc.Unimplemented error.
    	Unimplemented = Errf(codes.Unimplemented, "")
    
    	// Internal is an empty grpc.Internal error.
    	Internal = Errf(codes.Internal, "")
    
    	// Unavailable is an empty grpc.Unavailable error.
    	Unavailable = Errf(codes.Unavailable, "")
    
    	// DataLoss is an empty grpc.DataLoss error.
    	DataLoss = Errf(codes.DataLoss, "")
    )
    View Source
    var Tag = grpcCodeTag{errors.NewTagKey("gRPC Code")}

      Tag may be used to associate a gRPC status code with this error.

      The tag value MUST be a "google.golang.org/grpc/codes".Code.

      Functions

      func Code

      func Code(err error) codes.Code

        Code returns the gRPC code for a given error.

        In addition to the functionality of grpc.Code, this will unwrap any wrapped errors before asking for its code.

        func IsTransientCode

        func IsTransientCode(code codes.Code) bool

          IsTransientCode returns true if a given gRPC code is associated with a transient gRPC error type.

          func NewUnaryServerPanicCatcher

          func NewUnaryServerPanicCatcher(next grpc.UnaryServerInterceptor) grpc.UnaryServerInterceptor

            NewUnaryServerPanicCatcher returns a unary interceptor that catches panics in RPC handlers, recovers them and returns codes.Internal gRPC errors instead.

            It can be optionally chained with other interceptor.

            func ToGRPCErr

            func ToGRPCErr(err error) error

              ToGRPCErr is a shorthand for Errf(Code(err), "%s", err)

              func WrapIfTransient

              func WrapIfTransient(err error) error

                WrapIfTransient wraps the supplied gRPC error with a transient wrapper if it has a transient gRPC code, as determined by IsTransientCode.

                If the supplied error is nil, nil will be returned.

                Note that non-gRPC errors will have code grpc.Unknown, which is considered transient, and be wrapped. This function should only be used on gRPC errors.

                Types

                This section is empty.