errors

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

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

View Source
const ReasonKey = "reason"

ReasonKey is the context key carrying a condition reason for an error.

Variables

This section is empty.

Functions

func IsPermanent

func IsPermanent(err error) bool

IsPermanent reports whether err should stall until its input changes: invalid input, not found, unauthorized and conflicts.

func IsTransient

func IsTransient(err error) bool

IsTransient reports whether err should be retried with backoff: timeouts, unavailability and rate limiting.

func ReasonOf

func ReasonOf(err error) string

ReasonOf returns the condition reason an error carries, if any.

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"
	ErrCodeUnauthorized      ErrorCode = "UNAUTHORIZED"
	ErrCodeTimeout           ErrorCode = "TIMEOUT"
	ErrCodeInternal          ErrorCode = "INTERNAL"
	ErrCodeInvalidRequest    ErrorCode = "INVALID_REQUEST"
	ErrCodeRateLimitExceeded ErrorCode = "RATE_LIMIT_EXCEEDED"
	ErrCodeUnavailable       ErrorCode = "SERVICE_UNAVAILABLE"
	ErrCodeConflict          ErrorCode = "CONFLICT"
	ErrCodeCanceled          ErrorCode = "CANCELED"
)

Error codes. Values match NVIDIA/aicr's pkg/errors.

func CodeOf

func CodeOf(err error) ErrorCode

CodeOf returns the code of the first StructuredError in err's chain. A bare context.Canceled is CANCELED and a bare context.DeadlineExceeded is TIMEOUT; any other error is INTERNAL. A nil error has no code.

type StructuredError

type StructuredError struct {
	Code    ErrorCode
	Message string
	Context map[string]any
	Cause   error
}

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) Error

func (e *StructuredError) Error() string

Error implements error.

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) Unwrap

func (e *StructuredError) Unwrap() error

Unwrap returns the cause.

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.

Jump to

Keyboard shortcuts

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