apierror

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package apierror holds the errors a substrate server deliberately returns to its caller.

An apierror is not a gRPC status: it has no GRPCStatus method, so a status received from an upstream service never decides the code a server returns, however it is wrapped. To propagate an upstream code, check it at the call site and construct the apierror that says what it means to this server's caller. Anything that is neither an apierror nor a context error reaches the caller as codes.Internal.

There is one constructor per code a server chooses. OK and Unknown have none, and neither do Canceled and DeadlineExceeded: return or wrap the context's error instead, and Code and FromError map it.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Aborted

func Aborted(format string, args ...any) error

Aborted reports a request that lost a concurrency conflict, such as a version mismatch. Retrying from a fresh read can succeed.

func AlreadyExists

func AlreadyExists(format string, args ...any) error

AlreadyExists reports that a resource the request creates already exists.

func Code

func Code(err error) codes.Code

Code returns the code err reaches the caller with, the same as FromError(err).Code(): codes.OK for nil, and codes.Internal for an error that is neither an apierror nor a context error. It never reads a gRPC status.

func DataLoss

func DataLoss(format string, args ...any) error

DataLoss reports unrecoverable loss or corruption of data.

func FailedPrecondition

func FailedPrecondition(format string, args ...any) error

FailedPrecondition reports that the system is not in the state the request requires. Retrying is pointless until that state changes.

func FromError

func FromError(err error) (s *status.Status, ok bool)

FromError converts err to the status a server returns for it. The message is the apierror's own, without the context added by errors wrapping it. ok is false when err is neither an apierror nor a context error; the status is then codes.Internal with err's text, which the caller may reword.

func Internal

func Internal(format string, args ...any) error

Internal reports a server-side failure with a message chosen for the caller. A plain error also reaches the caller as codes.Internal, but with whatever text it carries.

func InvalidArgument

func InvalidArgument(format string, args ...any) error

InvalidArgument reports a request that is malformed regardless of the system's state.

func NotFound

func NotFound(format string, args ...any) error

NotFound reports that a resource the request names does not exist.

func PermissionDenied

func PermissionDenied(format string, args ...any) error

PermissionDenied reports an authenticated caller that may not perform the request.

func ResourceExhausted

func ResourceExhausted(format string, args ...any) error

ResourceExhausted reports that a quota or capacity limit refused the request.

func Unauthenticated

func Unauthenticated(format string, args ...any) error

Unauthenticated reports a caller whose identity could not be established.

func Unavailable

func Unavailable(format string, args ...any) error

Unavailable reports that the request was not acted on, so retrying it, here or elsewhere, is safe. Never use it for a failure partway through.

func Unimplemented

func Unimplemented(format string, args ...any) error

Unimplemented reports a request this server does not support.

Types

This section is empty.

Jump to

Keyboard shortcuts

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