Movatterモバイル変換


[0]ホーム

URL:


status

package
v1.77.0Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2025 License:Apache-2.0Imports:6Imported by:127,332

Details

Repository

github.com/grpc/grpc-go

Links

Documentation

Overview

Package status implements errors returned by gRPC. These errors areserialized and transmitted on the wire between server and client, and allowfor additional data to be transmitted via the Details field in the statusproto. gRPC service handlers should return an error created by thispackage, and gRPC clients should expect a corresponding error to bereturned from the RPC call.

This package upholds the invariants that a non-nil error may notcontain an OK code, and an OK code must result in a nil error.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

funcCodeadded inv1.9.0

func Code(errerror)codes.Code

Code returns the Code of the error if it is a Status error or if it wraps aStatus error. If that is not the case, it returns codes.OK if err is nil, orcodes.Unknown otherwise.

funcError

func Error(ccodes.Code, msgstring)error

Error returns an error representing c and msg. If c is OK, returns nil.

funcErrorProto

func ErrorProto(s *spb.Status)error

ErrorProto returns an error representing s. If s.Code is OK, returns nil.

funcErrorf

func Errorf(ccodes.Code, formatstring, a ...any)error

Errorf returns Error(c, fmt.Sprintf(format, a...)).

Types

typeStatus

type Status =status.Status

Status references google.golang.org/grpc/internal/status. It represents anRPC status code, message, and details. It is immutable and should becreated with New, Newf, or FromProto.https://godoc.org/google.golang.org/grpc/internal/status

funcConvertadded inv1.10.0

func Convert(errerror) *Status

Convert is a convenience function which removes the need to handle theboolean return value from FromError.

funcFromContextErroradded inv1.13.0

func FromContextError(errerror) *Status

FromContextError converts a context error or wrapped context error into aStatus. It returns a Status with codes.OK if err is nil, or a Status withcodes.Unknown if err is non-nil and not a context error.

funcFromError

func FromError(errerror) (s *Status, okbool)

FromError returns a Status representation of err.

  • If err was produced by this package or implements the method `GRPCStatus()*Status` and `GRPCStatus()` does not return nil, or if err wraps a typesatisfying this, the Status from `GRPCStatus()` is returned. For wrappederrors, the message returned contains the entire err.Error() text and notjust the wrapped status. In that case, ok is true.

  • If err is nil, a Status is returned with codes.OK and no message, and okis true.

  • If err implements the method `GRPCStatus() *Status` and `GRPCStatus()`returns nil (which maps to Codes.OK), or if err wraps a typesatisfying this, a Status is returned with codes.Unknown and err'sError() message, and ok is false.

  • Otherwise, err is an error not compatible with this package. In thiscase, a Status is returned with codes.Unknown and err's Error() message,and ok is false.

funcFromProto

func FromProto(s *spb.Status) *Status

FromProto returns a Status representing s.

funcNew

func New(ccodes.Code, msgstring) *Status

New returns a Status representing c and msg.

funcNewf

func Newf(ccodes.Code, formatstring, a ...any) *Status

Newf returns New(c, fmt.Sprintf(format, a...)).

Source Files

View all Source files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f orF : Jump to
y orY : Canonical URL
go.dev uses cookies from Google to deliver and enhance the quality of its services and to analyze traffic.Learn more.

[8]ページ先頭

©2009-2025 Movatter.jp