failure

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package failure owns provider-neutral inference failures shared by codecs, transports, and provider integrations.

Index

Constants

View Source
const MaxErrorBodyBytes = 64 << 10

MaxErrorBodyBytes is the maximum transient provider-error prefix parsed by APIErrorFromResponse. No bytes from that prefix are retained in APIError.

Variables

This section is empty.

Functions

This section is empty.

Types

type APIError

type APIError struct {
	Status int

	// Code is a provider error code from the closed allowlist below. It is
	// intentionally not a free-form provider message.
	Code string
	// ProviderCode is an additive descriptive alias for Code. Both fields are
	// normalized before they are emitted; NewAPIError populates both.
	ProviderCode string
	// RequestID is copied only from known request-ID headers and only when it
	// is bounded and printable. Raw response headers are never retained.
	RequestID string
	// RetryAfter is the server-advertised wait from a Retry-After header,
	// integer-seconds form only. Zero means absent or unparseable.
	RetryAfter time.Duration
	// contains filtered or unexported fields
}

func APIErrorFromResponse

func APIErrorFromResponse(status int, body []byte, headers http.Header, retryAfter time.Duration) *APIError

APIErrorFromResponse extracts only allowlisted provider codes and request IDs. The body is parsed transiently and is never copied into the returned error. The caller must bound body before calling this helper; this function also truncates defensively for direct callers.

func NewAPIError

func NewAPIError(status int, code, requestID string, retryAfter time.Duration) *APIError

NewAPIError constructs an APIError from already-sanitized fields. Raw provider messages, bodies, and headers have no representation in APIError.

func NewAPIErrorWithStatusText

func NewAPIErrorWithStatusText(status int, code, requestID string, retryAfter time.Duration, statusText string) *APIError

NewAPIErrorWithStatusText constructs an APIError with a bounded, gateway-owned status text. Provider response messages must use APIErrorFromResponse instead; arbitrary text is rejected and never stored.

func (*APIError) Error

func (e *APIError) Error() string

func (APIError) Format

func (e APIError) Format(state fmt.State, _ rune)

Format prevents fmt's default struct formatting from exposing the deprecated Body field or any future unsafe fields.

func (APIError) GoString

func (e APIError) GoString() string

func (APIError) LogValue

func (e APIError) LogValue() slog.Value

LogValue emits only the bounded, allowlisted diagnostics. In particular, it does not expose Body, headers, or provider response text.

type ModelMismatchError

type ModelMismatchError struct {
	BoundProvider    model.ProviderName
	RequestProvider  model.ProviderName
	BoundEndpoint    string
	RequestEndpoint  string
	BoundAPIFormat   model.APIFormat
	RequestAPIFormat model.APIFormat
}

func (*ModelMismatchError) Error

func (e *ModelMismatchError) Error() string

type NetworkError

type NetworkError struct {
	Err error
}

func (*NetworkError) Error

func (e *NetworkError) Error() string

func (*NetworkError) Unwrap

func (e *NetworkError) Unwrap() error

type ResponseBodyTooLargeError

type ResponseBodyTooLargeError struct{ Limit int }

ResponseBodyTooLargeError reports a bounded response that cannot safely be decoded. It contains only the configured bound.

func (*ResponseBodyTooLargeError) Error

func (e *ResponseBodyTooLargeError) Error() string

func (*ResponseBodyTooLargeError) Format

func (e *ResponseBodyTooLargeError) Format(state fmt.State, _ rune)

func (*ResponseBodyTooLargeError) GoString

func (e *ResponseBodyTooLargeError) GoString() string

Jump to

Keyboard shortcuts

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