errors

package module
v0.34.1 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2026 License: Apache-2.0 Imports: 11 Imported by: 20

README

errors - define, construct and manage service errors

Documentation

Index

Constants

View Source
const (
	HTTPStatusErrorMetadata = "aserto-http-statuscode"
)
View Source
const (
	MessageKey = "msg"
)

Variables

View Source
var (
	ErrUnknown = NewAsertoError("E00000", codes.Internal, http.StatusInternalServerError, "an unknown error has occurred")
)

Functions

func CustomErrorHandler

func CustomErrorHandler(
	ctx context.Context,
	gtw *runtime.ServeMux,
	runtimeMarshaler runtime.Marshaler,
	httpResponseWriter http.ResponseWriter,
	httpRequest *http.Request,
	err error,
)

func Logger added in v0.0.8

func Logger(err error) *zerolog.Logger

Logger retrieves the most inner logger associated with an error.

Types

type AsertoError

type AsertoError struct {
	Code     string
	GRPCCode codes.Code
	HTTPCode int
	Message  string
	// contains filtered or unexported fields
}

AsertoError represents a well known error coming from an Aserto service.

func CodeToAsertoError

func CodeToAsertoError(code string) *AsertoError

func FromGRPCStatus

func FromGRPCStatus(grpcStatus status.Status) *AsertoError

FromGRPCStatus returns an Aserto error based on a given grpcStatus. The details that are not of type errdetails.ErrorInfo are dropped. and if there are details from multiple errors, the aserto error will be constructed based on the first one.

func NewAsertoError

func NewAsertoError(code string, grpcCode codes.Code, httpCode int, msg string) *AsertoError

func UnwrapAsertoError

func UnwrapAsertoError(err error) *AsertoError

func (*AsertoError) Cause

func (e *AsertoError) Cause() error

func (*AsertoError) Copy

func (e *AsertoError) Copy() *AsertoError

func (*AsertoError) Ctx added in v0.0.8

func (e *AsertoError) Ctx(ctx context.Context) error

func (*AsertoError) Data

func (e *AsertoError) Data() map[string]string

func (*AsertoError) Err

func (e *AsertoError) Err(err error) *AsertoError

Err associates err with the AsertoError, replacing any error previously associated via Err.

func (*AsertoError) Error

func (e *AsertoError) Error() string

func (*AsertoError) ErrorInfo added in v0.34.1

func (e *AsertoError) ErrorInfo(reason string) *errdetails.ErrorInfo

ErrorInfo returns the errdetails.ErrorInfo for this error, with HTTPCode folded into Metadata under HTTPStatusErrorMetadata so it survives the grpc-gateway boundary (see CustomErrorHandler).

func (*AsertoError) Fields

func (e *AsertoError) Fields() map[string]any

func (*AsertoError) GRPCStatus

func (e *AsertoError) GRPCStatus() *status.Status

func (*AsertoError) MarshalZerologObject

func (e *AsertoError) MarshalZerologObject(event *zerolog.Event)

func (*AsertoError) Msg

func (e *AsertoError) Msg(message string) *AsertoError

func (*AsertoError) Msgf

func (e *AsertoError) Msgf(message string, args ...any) *AsertoError

func (*AsertoError) Str

func (e *AsertoError) Str(key, value string) *AsertoError

func (*AsertoError) Unwrap

func (e *AsertoError) Unwrap() error

type ContextError added in v0.0.8

type ContextError struct {
	Err error
	Ctx context.Context //nolint:containedctx
}

ContextError represents a standard error that can also encapsulate a context.

func WithContext added in v0.0.8

func WithContext(err error, ctx context.Context) *ContextError

func WrapContext added in v0.0.8

func WrapContext(err error, ctx context.Context, message string) *ContextError

func WrapfContext added in v0.0.8

func WrapfContext(err error, ctx context.Context, format string, args ...any) *ContextError

func (*ContextError) Cause added in v0.0.8

func (ce *ContextError) Cause() error

func (*ContextError) Error added in v0.0.8

func (ce *ContextError) Error() string

func (*ContextError) Unwrap added in v0.0.8

func (ce *ContextError) Unwrap() error

Jump to

Keyboard shortcuts

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