errors

package
v0.0.0-...-0f436f8 Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SVC string = "HRLD"
)

Variables

This section is empty.

Functions

func GetStackTrace

func GetStackTrace() string

GetStackTrace returns a human-readable stack trace

func HandleSpanError

func HandleSpanError(ctx context.Context, span trace.Span, log *zap.Logger, msg string, err error, extraFields ...zap.Field)

func IsSameError

func IsSameError(err error, code ErrorCode) bool

IsSameError checks if the error is the same as the given ErrorCode

func Raise

func Raise(code ErrorCode, msg string, errToWrap error) error

Raise is a general util to construct domain errors

func RaiseToSentry

func RaiseToSentry(ctx context.Context, err error)

RaiseToSentry raises the error to Sentry

func RecoverPanic

func RecoverPanic(msg string) func()

RecoverPanic can be deferred to capture and log a panic

Types

type AppError

type AppError struct {
	ErrorCode ErrorCode // unique error code
	Message   string    // optional human-readable message
	Cause     error     // wrapped error
}

AppError represents an application error with a code, message, cause, and extra data

func AsAppError

func AsAppError(err error) (*AppError, bool)

AsAppError tries to cast the given error to an AppError

func (*AppError) Error

func (ae *AppError) Error() string

func (*AppError) Format

func (ae *AppError) Format(s fmt.State, verb rune)

func (*AppError) GetCode

func (ae *AppError) GetCode() string

func (*AppError) GetErrorCode

func (ae *AppError) GetErrorCode() ErrorCode

func (*AppError) GetMessage

func (ae *AppError) GetMessage() string

func (*AppError) Unwrap

func (ae *AppError) Unwrap() error

type ErrorCode

type ErrorCode string

ErrorCode type

const (
	// System errors
	ErrInternalError ErrorCode = "SYS-00"

	// Fact errors
	ErrFactInvalidKey       ErrorCode = "FACT-01"
	ErrFactInvalidType      ErrorCode = "FACT-02"
	ErrFactInvalidOccuredAt ErrorCode = "FACT-03"
	ErrFactInvalidField     ErrorCode = "FACT-04"
	ErrFactMarshalFailed    ErrorCode = "FACT-05"

	// Cache errors
	ErrCacheCallFailed ErrorCode = "CACHE-01"

	// Kafka errors
	ErrKafkaProducerCreationFailed ErrorCode = "KAFKA-01"
	ErrKafkaProduceFailed          ErrorCode = "KAFKA-02"

	// K8s errors
	ErrK8sInformerCreationFailed ErrorCode = "K8S-01"
	ErrK8sCacheFailed            ErrorCode = "K8S-02"
)

func ExtractErrorCode

func ExtractErrorCode(err error) (ErrorCode, bool)

ExtractErrorCode extracts the ErrorCode from an error, if it is an AppError

Jump to

Keyboard shortcuts

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