Documentation
¶
Index ¶
- Constants
- Variables
- func As(err error, target any) bool
- func GetHTTPStatusCode(err error) int
- func Is(err, target error) bool
- func IsCircularDependency(err error) bool
- func IsContextCancelled(err error) bool
- func IsServiceAlreadyExists(err error) bool
- func IsServiceNotFound(err error) bool
- func IsTimeout(err error) bool
- func IsValidationError(err error) bool
- func Join(errs ...error) error
- func New(text string) error
- func Unwrap(err error) error
- type ForgeError
- func ErrCircularDependency(services []string) *ForgeError
- func ErrConfigError(message string, cause error) *ForgeError
- func ErrContainerError(operation string, cause error) *ForgeError
- func ErrContextCancelled(operation string) *ForgeError
- func ErrDependencyNotFound(deps ...string) *ForgeError
- func ErrHealthCheckFailed(serviceName string, cause error) *ForgeError
- func ErrInvalidConfig(configKey string, cause error) *ForgeError
- func ErrLifecycleError(phase string, cause error) *ForgeError
- func ErrServiceAlreadyExists(serviceName string) *ForgeError
- func ErrServiceNotFound(serviceName string) *ForgeError
- func ErrServiceStartFailed(serviceName string, cause error) *ForgeError
- func ErrTimeoutError(operation string, timeout time.Duration) *ForgeError
- func ErrValidationError(field string, cause error) *ForgeError
- type HTTPError
- type IHTTPError
- type ServiceError
- type Severity
- type ValidationError
Constants ¶
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.
const ( SeverityError = errs.SeverityError SeverityWarning = errs.SeverityWarning SeverityInfo = errs.SeverityInfo )
Variables ¶
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.
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 ¶
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 ¶
GetHTTPStatusCode extracts HTTP status code from error, returns 500 if not found.
func Is ¶
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 ¶
IsCircularDependency checks if the error is a circular dependency error.
func IsContextCancelled ¶
IsContextCancelled checks if the error is a context cancelled error.
func IsServiceAlreadyExists ¶
IsServiceAlreadyExists checks if the error is a service already exists error.
func IsServiceNotFound ¶
IsServiceNotFound checks if the error is a service not found error.
func IsValidationError ¶
IsValidationError checks if the error is a validation error.
func Join ¶
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+.
Types ¶
type ForgeError ¶
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 ¶
Error returns the error message, falling back to HTTP status text if no message is set.
func (*HTTPError) ResponseBody ¶
ResponseBody returns the response body for the HTTP error.
func (*HTTPError) StatusCode ¶
StatusCode returns the HTTP status code.
type IHTTPError ¶ added in v0.9.0
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 ¶
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 ValidationError ¶
type ValidationError = errs.ValidationError
ValidationError represents a validation error.