package status
import "google.golang.org/grpc/internal/status"
Package status implements errors returned by gRPC. These errors are serialized and transmitted on the wire between server and client, and allow for additional data to be transmitted via the Details field in the status proto. gRPC service handlers should return an error created by this package, and gRPC clients should expect a corresponding error to be returned from the RPC call.
This package upholds the invariants that a non-nil error may not contain an OK code, and an OK code must result in a nil error.
Index ¶
- func Err(c codes.Code, msg string) error
- func Errorf(c codes.Code, format string, a ...any) error
- func IsRestrictedControlPlaneCode(s *Status) bool
- type Error
- func (e *Error) Error() string
- func (e *Error) GRPCStatus() *Status
- func (e *Error) Is(target error) bool
- type Status
- func FromProto(s *spb.Status) *Status
- func New(c codes.Code, msg string) *Status
- func NewWithProto(code codes.Code, message string, statusProto []string) *Status
- func Newf(c codes.Code, format string, a ...any) *Status
- func (s *Status) Code() codes.Code
- func (s *Status) Details() []any
- func (s *Status) Err() error
- func (s *Status) Message() string
- func (s *Status) Proto() *spb.Status
- func (s *Status) String() string
- func (s *Status) WithDetails(details ...protoadapt.MessageV1) (*Status, error)
Functions ¶
func Err ¶
Err returns an error representing c and msg. If c is OK, returns nil.
func Errorf ¶
Errorf returns Error(c, fmt.Sprintf(format, a...)).
func IsRestrictedControlPlaneCode ¶
IsRestrictedControlPlaneCode returns whether the status includes a code restricted for control plane usage as defined by gRFC A54.
Types ¶
type Error ¶
type Error struct {
// contains filtered or unexported fields
}
Error wraps a pointer of a status proto. It implements error and Status, and a nil *Error should never be returned by this package.
func (*Error) Error ¶
func (*Error) GRPCStatus ¶
GRPCStatus returns the Status represented by se.
func (*Error) Is ¶
Is implements future error.Is functionality. A Error is equivalent if the code and message are identical.
type Status ¶
type Status struct {
// contains filtered or unexported fields
}
Status represents an RPC status code, message, and details. It is immutable and should be created with New, Newf, or FromProto.
func FromProto ¶
FromProto returns a Status representing s.
func New ¶
New returns a Status representing c and msg.
func NewWithProto ¶
NewWithProto returns a new status including details from statusProto. This is meant to be used by the gRPC library only.
func Newf ¶
Newf returns New(c, fmt.Sprintf(format, a...)).
func (*Status) Code ¶
Code returns the status code contained in s.
func (*Status) Details ¶
Details returns a slice of details messages attached to the status. If a detail cannot be decoded, the error is returned in place of the detail. If the detail can be decoded, the proto message returned is of the same type that was given to WithDetails().
func (*Status) Err ¶
Err returns an immutable error representing s; returns nil if s.Code() is OK.
func (*Status) Message ¶
Message returns the message contained in s.
func (*Status) Proto ¶
Proto returns s's status as an spb.Status proto message.
func (*Status) String ¶
func (*Status) WithDetails ¶
func (s *Status) WithDetails(details ...protoadapt.MessageV1) (*Status, error)
WithDetails returns a new status with the provided details messages appended to the status. If any errors are encountered, it returns nil and the first error encountered.
Source Files ¶
status.go
- Version
- v1.70.0 (latest)
- Published
- Jan 23, 2025
- Platform
- linux/amd64
- Imports
- 7 packages
- Last checked
- 19 hours ago –
Tools for package owners.