Documentation
¶
Overview ¶
Package errors provides the operator's structured errors.
The codes match NVIDIA/aicr's pkg/errors vocabulary, so an AICR exit category maps onto the same code here. The operator imports no AICR package, so this is a separate, smaller implementation of the same shape.
Index ¶
Constants ¶
const ReasonKey = "reason"
ReasonKey is the context key carrying a condition reason for an error.
Variables ¶
This section is empty.
Functions ¶
func IsPermanent ¶
IsPermanent reports whether err should stall until its input changes: invalid input, not found, unauthorized and conflicts.
func IsTransient ¶
IsTransient reports whether err should be retried with backoff: timeouts, unavailability and rate limiting.
Types ¶
type ErrorCode ¶
type ErrorCode string
ErrorCode classifies an error for handling: permanent codes wait for an input change, transient codes retry with backoff.
const ( ErrCodeNotFound ErrorCode = "NOT_FOUND" ErrCodeTimeout ErrorCode = "TIMEOUT" ErrCodeInternal ErrorCode = "INTERNAL" ErrCodeInvalidRequest ErrorCode = "INVALID_REQUEST" ErrCodeRateLimitExceeded ErrorCode = "RATE_LIMIT_EXCEEDED" ErrCodeConflict ErrorCode = "CONFLICT" ErrCodeCanceled ErrorCode = "CANCELED" )
Error codes. Values match NVIDIA/aicr's pkg/errors.
type StructuredError ¶
StructuredError is an error with a code, a message safe to surface in conditions and Events, and optional context for structured logs.
func New ¶
func New(code ErrorCode, message string) *StructuredError
New returns a StructuredError without a cause.
func Wrap ¶
func Wrap(code ErrorCode, message string, cause error) *StructuredError
Wrap returns a StructuredError that wraps cause.
func WrapCtxErr ¶
func WrapCtxErr(cause error, fallbackCode ErrorCode, message string) *StructuredError
WrapCtxErr wraps cause, preserving cancellation and deadline as CANCELED and TIMEOUT so callers never misreport shutdown or a bounded wait as an internal failure. A Kubernetes API refusal that no retry of the same request can change (an invalid object, an admission or authorization denial, a malformed or oversized request) is permanent, so the caller fails or stalls with its cause instead of retrying until a deadline; conflicts, timeouts, throttling and server errors stay transient. Other causes get fallbackCode.
func (*StructuredError) Is ¶
func (e *StructuredError) Is(target error) bool
Is reports whether target is a StructuredError with the same code, so errors.Is(err, New(ErrCodeTimeout, "")) matches any timeout.
func (*StructuredError) WithContext ¶
func (e *StructuredError) WithContext(ctx map[string]any) *StructuredError
WithContext returns a copy of e with the given key/value context added.
func (*StructuredError) WithReason ¶
func (e *StructuredError) WithReason(reason string) *StructuredError
WithReason records the condition reason a controller reports for e.