connect-errors provides opinionated constructors for Connect errors. Each
constructor selects a Connect code, attaches the corresponding structured
google.rpc error details, and records an event on the span in the supplied
context.
go get github.com/pbrpc/connect-errorsreturn connecterrors.InvalidArgument(
ctx,
"validation failed",
connecterrors.FieldViolation{
Field: "email",
Description: "invalid format",
},
)| Function | Connect code | Structured details |
|---|---|---|
InvalidArgument |
InvalidArgument |
google.rpc.BadRequest |
AlreadyExists |
AlreadyExists |
google.rpc.PreconditionFailure |
NotFound |
NotFound |
google.rpc.ResourceInfo |
RateLimited |
ResourceExhausted |
google.rpc.RetryInfo, QuotaFailure |
PreconditionFailed |
FailedPrecondition |
google.rpc.PreconditionFailure |
Internal |
Internal |
google.rpc.ErrorInfo |
WithHelp and WithLocalizedMessage attach google.rpc.Help and
google.rpc.LocalizedMessage details to an existing Connect error. If the
given error is not a Connect error, they return it unchanged.
AlreadyExists uses RESOURCE_ALREADY_EXISTS as its precondition violation
type. RateLimited uses rate_limit as its quota subject and defaults an empty
message to rate limit exceeded. NotFound formats its message as
<resource type> not found.