Skip to content

About

Opinionated constructors for Connect errors.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

5 Commits

Folders and files

Repository files navigation

connect-errors

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.

Installation

go get github.com/pbrpc/connect-errors

Usage

return connecterrors.InvalidArgument(
	ctx,
	"validation failed",
	connecterrors.FieldViolation{
		Field:       "email",
		Description: "invalid format",
	},
)

Constructors

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.

Contract values

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.

About

Opinionated constructors for Connect errors.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Contributors

Languages