awserr

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package awserr provides shared sentinel errors for AWS service stubs. Service packages wrap these sentinels so callers can use errors.Is to match any service error against a shared sentinel.

Index

Constants

View Source
const ErrAlreadyExists sentinelError = "resource already exists"

ErrAlreadyExists is a sentinel indicating a resource already exists.

View Source
const ErrConflict sentinelError = "conflict"

ErrConflict is a sentinel indicating a conflicting state or concurrent operation.

View Source
const ErrInvalidParameter sentinelError = "invalid parameter"

ErrInvalidParameter is a sentinel indicating an invalid or missing parameter.

View Source
const ErrNotFound sentinelError = "resource not found"

ErrNotFound is a sentinel indicating a requested resource does not exist.

Variables

This section is empty.

Functions

func New

func New(msg string, sentinel error) error

New creates an error with the given message that wraps the given sentinel. This preserves the service-specific error message while enabling errors.Is to match the shared sentinel.

func Newf

func Newf(msg string, sentinel error, args ...any) error

Newf creates an error with a formatted message that wraps the given sentinel.

func Write

func Write(c *echo.Context, proto Protocol, e APIError) error

Write serialises e onto c using the envelope for proto, setting the appropriate Content-Type (and X-Amz-Crc32 for the JSON protocols) and the HTTP status from e.HTTPStatus. It returns the echo error from the underlying write so handlers can `return awserr.Write(...)` directly.

Types

type APIError

type APIError struct {
	// Code is the AWS error code (e.g. "ResourceNotFoundException"). For the
	// JSON protocols it may include the Coral namespace prefix
	// (e.g. "com.amazonaws.dynamodb.v20120810#ResourceNotFoundException").
	Code string
	// Message is the human-readable error message.
	Message string
	// HTTPStatus is the HTTP status code to return (e.g. 400, 404, 409).
	HTTPStatus int
}

APIError is a protocol-agnostic description of an AWS API error. Services declare a table mapping their wrapped sentinel errors (see New) to an APIError, then call Write to serialise it for the wire.

func Classify

func Classify(err error, table map[error]APIError, fallback APIError) APIError

Classify maps err to an APIError using table. Each table key is a sentinel (or wrapped sentinel) and is matched against err with errors.Is, so callers can wrap sentinels with New/Newf and still classify them here. The first matching entry wins; if nothing matches, fallback is returned (typically a 500 InternalFailure). The matched entry's Message is overridden with err's message when err carries a more specific one via New/Newf.

func (APIError) Error

func (e APIError) Error() string

Error implements the error interface so an APIError can itself be returned and matched with errors.As.

type Protocol

type Protocol int

Protocol identifies the AWS wire protocol used to encode an error envelope. Different AWS services speak different protocols, so the same logical error (an APIError) must be serialised differently depending on the service.

const (
	// ProtocolJSON10 is the AWS JSON 1.0 protocol (e.g. DynamoDB). Errors are
	// encoded as {"__type":"<Code>","message":"<Message>"} with a CRC32 header.
	ProtocolJSON10 Protocol = iota
	// ProtocolJSON11 is the AWS JSON 1.1 protocol (e.g. Kinesis, many newer
	// services). Same envelope as JSON 1.0 with a different Content-Type.
	ProtocolJSON11
	// ProtocolQueryXML is the AWS Query protocol (e.g. classic SQS/SNS/EC2).
	// Errors are wrapped in <ErrorResponse><Error>...</Error></ErrorResponse>.
	ProtocolQueryXML
	// ProtocolRestXML is the AWS REST-XML protocol (e.g. S3). Errors are
	// encoded as a bare <Error>...</Error> document.
	ProtocolRestXML
)

Jump to

Keyboard shortcuts

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