errors

package
v0.9.3 Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2026 License: Apache-2.0 Imports: 6 Imported by: 9

Documentation

Index

Constants

View Source
const (
	CodeConfigError          = "CONFIG_ERROR"
	CodeValidationError      = "VALIDATION_ERROR"
	CodeLifecycleError       = "LIFECYCLE_ERROR"
	CodeContextCancelled     = "CONTEXT_CANCELLED"
	CodeServiceNotFound      = "SERVICE_NOT_FOUND"
	CodeServiceAlreadyExists = "SERVICE_ALREADY_EXISTS"
	CodeCircularDependency   = "CIRCULAR_DEPENDENCY"
	CodeInvalidConfig        = "INVALID_CONFIG"
	CodeTimeoutError         = "TIMEOUT_ERROR"
	CodeHealthCheckFailed    = "HEALTH_CHECK_FAILED"
	CodeServiceStartFailed   = "SERVICE_START_FAILED"
)

Error code constants for structured errors.

View Source
const (
	SeverityError   = errs.SeverityError
	SeverityWarning = errs.SeverityWarning
	SeverityInfo    = errs.SeverityInfo
)

Variables

View Source
var (

	// ErrInvalidFactory indicates a factory function is invalid.
	ErrInvalidFactory   = errs.New("factory must be a function")
	ErrTypeMismatch     = errs.New("service type mismatch")
	ErrLifecycleTimeout = errs.New("lifecycle operation timed out")
	ErrContainerStarted = errs.New("container already started")
	ErrContainerStopped = errs.New("container already stopped")
	ErrScopeEnded       = errs.New("scope already ended")
)

DI/service errors.

View Source
var (
	// ErrServiceNotFoundSentinel is a sentinel error for service not found.
	ErrServiceNotFoundSentinel = &ForgeError{Code: CodeServiceNotFound}

	// ErrServiceAlreadyExistsSentinel is a sentinel error for service already exists.
	ErrServiceAlreadyExistsSentinel = &ForgeError{Code: CodeServiceAlreadyExists}

	// ErrCircularDependencySentinel is a sentinel error for circular dependency.
	ErrCircularDependencySentinel = &ForgeError{Code: CodeCircularDependency}

	// ErrInvalidConfigSentinel is a sentinel error for invalid config.
	ErrInvalidConfigSentinel = &ForgeError{Code: CodeInvalidConfig}

	// ErrValidationErrorSentinel is a sentinel error for validation errors.
	ErrValidationErrorSentinel = &ForgeError{Code: CodeValidationError}

	// ErrLifecycleErrorSentinel is a sentinel error for lifecycle errors.
	ErrLifecycleErrorSentinel = &ForgeError{Code: CodeLifecycleError}

	// ErrContextCancelledSentinel is a sentinel error for context cancellation.
	ErrContextCancelledSentinel = &ForgeError{Code: CodeContextCancelled}

	// ErrTimeoutErrorSentinel is a sentinel error for timeout errors.
	ErrTimeoutErrorSentinel = &ForgeError{Code: CodeTimeoutError}

	// ErrConfigErrorSentinel is a sentinel error for config errors.
	ErrConfigErrorSentinel = &ForgeError{Code: CodeConfigError}
)

Sentinel errors that can be used with errors.Is comparisons.

Functions

func As

func As(err error, target any) bool

As finds the first error in err's chain that matches target, and if so, sets target to that error value and returns true. Otherwise, it returns false. This is a convenience wrapper around errors.As from the standard library.

Example:

var httpErr *HTTPError
if As(err, &httpErr) {
    // handle HTTP error with httpErr.Code
}

func GetHTTPStatusCode

func GetHTTPStatusCode(err error) int

GetHTTPStatusCode extracts HTTP status code from error, returns 500 if not found.

func Is

func Is(err, target error) bool

Is reports whether any error in err's chain matches target. This is a convenience wrapper around errors.Is from the standard library.

Example:

err := ErrServiceNotFound("auth")
if Is(err, &ForgeError{Code: "SERVICE_NOT_FOUND"}) {
    // handle service not found
}

func IsCircularDependency

func IsCircularDependency(err error) bool

IsCircularDependency checks if the error is a circular dependency error.

func IsContextCancelled

func IsContextCancelled(err error) bool

IsContextCancelled checks if the error is a context cancelled error.

func IsServiceAlreadyExists

func IsServiceAlreadyExists(err error) bool

IsServiceAlreadyExists checks if the error is a service already exists error.

func IsServiceNotFound

func IsServiceNotFound(err error) bool

IsServiceNotFound checks if the error is a service not found error.

func IsTimeout

func IsTimeout(err error) bool

IsTimeout checks if the error is a timeout error.

func IsValidationError

func IsValidationError(err error) bool

IsValidationError checks if the error is a validation error.

func Join

func Join(errs ...error) error

Join returns an error that wraps the given errors. Any nil error values are discarded. This is a convenience wrapper around errors.Join from the standard library. Requires Go 1.20+.

func New

func New(text string) error

New returns an error that formats as the given text. This is a convenience wrapper around errors.New from the standard library.

func Unwrap

func Unwrap(err error) error

Unwrap returns the result of calling the Unwrap method on err, if err's type contains an Unwrap method returning error. Otherwise, Unwrap returns nil. This is a convenience wrapper around errors.Unwrap from the standard library.

Types

type ForgeError

type ForgeError = errs.Error

ForgeError represents a structured error with context.

func ErrCircularDependency

func ErrCircularDependency(services []string) *ForgeError

func ErrConfigError

func ErrConfigError(message string, cause error) *ForgeError

ErrConfigError creates a config error.

func ErrContainerError

func ErrContainerError(operation string, cause error) *ForgeError

func ErrContextCancelled

func ErrContextCancelled(operation string) *ForgeError

func ErrDependencyNotFound

func ErrDependencyNotFound(deps ...string) *ForgeError

func ErrHealthCheckFailed

func ErrHealthCheckFailed(serviceName string, cause error) *ForgeError

func ErrInvalidConfig

func ErrInvalidConfig(configKey string, cause error) *ForgeError

func ErrLifecycleError

func ErrLifecycleError(phase string, cause error) *ForgeError

ErrLifecycleError creates a lifecycle error.

func ErrServiceAlreadyExists

func ErrServiceAlreadyExists(serviceName string) *ForgeError

func ErrServiceNotFound

func ErrServiceNotFound(serviceName string) *ForgeError

func ErrServiceStartFailed

func ErrServiceStartFailed(serviceName string, cause error) *ForgeError

func ErrTimeoutError

func ErrTimeoutError(operation string, timeout time.Duration) *ForgeError

func ErrValidationError

func ErrValidationError(field string, cause error) *ForgeError

ErrValidationError creates a validation error.

type HTTPError

type HTTPError struct {
	ForgeError

	HttpStatusCode int
}

func (*HTTPError) Error

func (e *HTTPError) Error() string

Error returns the error message, falling back to HTTP status text if no message is set.

func (*HTTPError) ResponseBody

func (e *HTTPError) ResponseBody() any

ResponseBody returns the response body for the HTTP error.

func (*HTTPError) StatusCode

func (e *HTTPError) StatusCode() int

StatusCode returns the HTTP status code.

func (*HTTPError) Unwrap

func (e *HTTPError) Unwrap() error

Unwrap returns the underlying error.

type IHTTPError added in v0.9.0

type IHTTPError = errs.HTTPError

IHTTPError represents the interface for HTTP errors with status codes.

func BadRequest

func BadRequest(message string) IHTTPError

func Forbidden

func Forbidden(message string) IHTTPError

func InternalError

func InternalError(err error) IHTTPError

func NewHTTPError

func NewHTTPError(code int, message string) IHTTPError

NewHTTPError creates a new HTTP error with the given status code and message.

func NotFound

func NotFound(message string) IHTTPError

func Unauthorized

func Unauthorized(message string) IHTTPError

type ServiceError

type ServiceError struct {
	Service   string
	Operation string
	Err       error
}

ServiceError wraps service-specific errors.

func NewServiceError

func NewServiceError(service, operation string, err error) *ServiceError

NewServiceError creates a new service error.

func (*ServiceError) Error

func (e *ServiceError) Error() string

func (*ServiceError) Is

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

Is implements errors.Is interface for ServiceError.

func (*ServiceError) Unwrap

func (e *ServiceError) Unwrap() error

type Severity

type Severity = errs.Severity

Severity represents the severity of a validation issue.

type ValidationError

type ValidationError = errs.ValidationError

ValidationError represents a validation error.

Jump to

Keyboard shortcuts

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