errors

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetContext

func GetContext(err error) map[string]interface{}

GetContext returns the error context

func IsType

func IsType(err error, errType ErrorType) bool

IsType checks if an error is of a specific type

Types

type ErrorType

type ErrorType string

ErrorType represents the type of error

const (
	// ErrorTypeUnknown is for unknown errors
	ErrorTypeUnknown ErrorType = "unknown"

	// ErrorTypeValidation is for validation errors
	ErrorTypeValidation ErrorType = "validation"

	// ErrorTypeNotFound is for resource not found errors
	ErrorTypeNotFound ErrorType = "not_found"

	// ErrorTypeConflict is for conflict errors
	ErrorTypeConflict ErrorType = "conflict"

	// ErrorTypeInternal is for internal server errors
	ErrorTypeInternal ErrorType = "internal"

	// ErrorTypeTimeout is for timeout errors
	ErrorTypeTimeout ErrorType = "timeout"

	// ErrorTypeAuthentication is for authentication errors
	ErrorTypeAuthentication ErrorType = "authentication"

	// ErrorTypeAuthorization is for authorization errors
	ErrorTypeAuthorization ErrorType = "authorization"

	// ErrorTypeNetwork is for network-related errors
	ErrorTypeNetwork ErrorType = "network"

	// ErrorTypeConfiguration is for configuration errors
	ErrorTypeConfiguration ErrorType = "configuration"
)

func GetType

func GetType(err error) ErrorType

GetType returns the error type

type S9sError

type S9sError struct {
	Type    ErrorType
	Message string
	Cause   error
	Context map[string]interface{}
	Stack   []StackFrame
}

S9sError represents a structured error with additional context

func Config

func Config(message string) *S9sError

Config creates a configuration error

func Configf

func Configf(format string, args ...interface{}) *S9sError

Configf creates a configuration error with formatted message

func Forbidden

func Forbidden(message string) *S9sError

Forbidden creates an authorization error

func Internal

func Internal(message string) *S9sError

Internal creates an internal error

func Internalf

func Internalf(format string, args ...interface{}) *S9sError

Internalf creates an internal error with formatted message

func Invalid

func Invalid(field, reason string) *S9sError

Invalid creates a validation error

func Invalidf

func Invalidf(format string, args ...interface{}) *S9sError

Invalidf creates a validation error with formatted message

func Network

func Network(message string) *S9sError

Network creates a network error

func New

func New(errType ErrorType, message string) *S9sError

New creates a new S9sError

func Newf

func Newf(errType ErrorType, format string, args ...interface{}) *S9sError

Newf creates a new S9sError with formatted message

func NotFound

func NotFound(resource string) *S9sError

NotFound creates a not found error

func NotFoundf

func NotFoundf(format string, args ...interface{}) *S9sError

NotFoundf creates a not found error with formatted message

func Timeout

func Timeout(operation string) *S9sError

Timeout creates a timeout error

func Unauthorized

func Unauthorized(message string) *S9sError

Unauthorized creates an authentication error

func Wrap

func Wrap(err error, errType ErrorType, message string) *S9sError

Wrap wraps an existing error with additional context

func Wrapf

func Wrapf(err error, errType ErrorType, format string, args ...interface{}) *S9sError

Wrapf wraps an existing error with formatted message

func (*S9sError) Error

func (e *S9sError) Error() string

Error implements the error interface

func (*S9sError) Is

func (e *S9sError) Is(target error) bool

Is checks if the error is of a specific type

func (*S9sError) Unwrap

func (e *S9sError) Unwrap() error

Unwrap returns the underlying error

func (*S9sError) WithContext

func (e *S9sError) WithContext(key string, value interface{}) *S9sError

WithContext adds context to the error

type StackFrame

type StackFrame struct {
	Function string
	File     string
	Line     int
}

StackFrame represents a single frame in the call stack

Jump to

Keyboard shortcuts

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