Documentation
¶
Overview ¶
Package xerr defines categorized errors with stable kinds for transport and application boundaries. Callers can inspect the category while preserving the underlying cause.
Index ¶
- Constants
- func ErrChain(err error) []error
- func IsDev() bool
- func IsTransient(err error) bool
- func MapTransportError(err error) error
- func Print(err error)
- func Sprint(err error) string
- type AppError
- func BadRequest(msg string, cause ...error) *AppError
- func Canceled(msg string, cause ...error) *AppError
- func CircuitBreaker(msg string, cause ...error) *AppError
- func Conflict(msg string, cause ...error) *AppError
- func Database(msg string, cause ...error) *AppError
- func Forbidden(msg string, cause ...error) *AppError
- func From(err error) *AppError
- func FromPublic(response ErrorResponse) (*AppError, bool)
- func Internal(msg string, cause ...error) *AppError
- func MethodNotAllowed(msg string, cause ...error) *AppError
- func NotFound(msg string, cause ...error) *AppError
- func PanicRecovery(recovered any) *AppError
- func RateLimit(msg string, cause ...error) *AppError
- func ServiceUnavailable(msg string, cause ...error) *AppError
- func Shutdown(msg string, cause ...error) *AppError
- func Timeout(msg string, cause ...error) *AppError
- func TooManyRequests(msg string, cause ...error) *AppError
- func Unauthorized(msg string, cause ...error) *AppError
- func Unavailable(msg string, cause ...error) *AppError
- func Validation(msg string, cause ...error) *AppError
- type ErrorResponse
- type Kind
- type ValidationDetail
- type ValidationDetails
Constants ¶
const RemoteErrorHeader = "Nexss-Error"
RemoteErrorHeader marks a transport reply whose payload is an ErrorResponse. It is intentionally transport-neutral so all adapters share one safe-error contract.
Variables ¶
This section is empty.
Functions ¶
func IsTransient ¶
IsTransient is the package-level predicate used by retry and circuit-breaker logic.
func MapTransportError ¶
MapTransportError converts raw transport/network errors into the xerr taxonomy. Call this at every adapter boundary (HTTP, NATS, gRPC).
Types ¶
type AppError ¶
type AppError struct {
Kind Kind
Message string
Cause error
Stack []uintptr
ValidationDetails ValidationDetails
}
AppError is the single error type for all application errors.
func BadRequest ¶
func CircuitBreaker ¶
func FromPublic ¶
func FromPublic(response ErrorResponse) (*AppError, bool)
FromPublic reconstructs a safe AppError from an ErrorResponse received over a trusted transport boundary. It never restores a remote cause or stack trace. The bool is false when the response does not contain a recognized Nexss kind.
func MethodNotAllowed ¶
func PanicRecovery ¶
PanicRecovery wraps a recovered panic value as an Internal error with stack trace.
func ServiceUnavailable ¶
func TooManyRequests ¶
func Unauthorized ¶
func Unavailable ¶
func Validation ¶
Validation creates a typed validation error with structured details.
func (*AppError) IsTransient ¶
IsTransient reports whether the error may succeed on retry. Used by RetryMiddleware and circuit breakers.
func (*AppError) Public ¶
func (e *AppError) Public(reqID string) ErrorResponse
Public returns a safe, client-facing representation. Internal details never leak.
type ErrorResponse ¶
type ErrorResponse struct {
Error string `json:"error"`
Message string `json:"message"`
RequestID string `json:"request_id,omitempty"`
Details ValidationDetails `json:"details,omitempty"`
}
ErrorResponse is the public contract sent to clients — never expose internals.
type Kind ¶
type Kind string
Kind is the machine-readable error category.
const ( KindBadRequest Kind = "BadRequest" KindForbidden Kind = "Forbidden" KindNotFound Kind = "NotFound" KindConflict Kind = "Conflict" KindValidation Kind = "Validation" KindTooManyRequests Kind = "TooManyRequests" KindTimeout Kind = "Timeout" KindInternal Kind = "Internal" // Extended kinds KindMethodNotAllowed Kind = "MethodNotAllowed" KindRateLimit Kind = "RateLimit" KindCanceled Kind = "Canceled" KindDatabase Kind = "Database" KindShutdown Kind = "Shutdown" KindCircuitBreaker Kind = "CircuitBreaker" )
type ValidationDetail ¶
type ValidationDetail struct {
Field string `json:"field"`
Validation string `json:"validation"`
Value string `json:"value,omitempty"`
}
ValidationDetail describes a single field validation failure.
func (ValidationDetail) String ¶
func (v ValidationDetail) String() string
type ValidationDetails ¶
type ValidationDetails []ValidationDetail