errors

package
v0.25.2 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package errors holds the SDK's error model. TerminalError and its helpers live in terminal.go; RetryableError and its helpers in retryable.go; the shared Code and the cross-cutting CodeOption live here.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsRetryableError added in v0.25.0

func IsRetryableError(err error) bool

IsRetryableError reports whether err is, or wraps, a RetryableError.

func IsTerminalError added in v0.11.0

func IsTerminalError(err error) bool

IsTerminalError reports whether err is, or wraps, a TerminalError.

Types

type Code

type Code uint16

Code is a numeric status code for an error, typically a HTTP status code.

const DefaultCode Code = 500

DefaultCode is the code assigned to an error when none is provided.

type CodeOption added in v0.25.0

type CodeOption struct {
	// contains filtered or unexported fields
}

CodeOption sets the status code. It is shared: it satisfies both TerminalErrorOption and RetryableErrorOption, so the same option works for either error type.

func WithCode added in v0.25.0

func WithCode(code Code) CodeOption

WithCode sets the status code on a terminal or retryable error.

type MetadataOption added in v0.25.0

type MetadataOption struct {
	// contains filtered or unexported fields
}

MetadataOption sets metadata. It is shared across everything that accepts metadata: terminal errors, service definitions and handlers (and merges with any metadata already set). It deliberately lives here, alongside the private terminalError it must reach, while also satisfying the options package's service/handler interfaces.

func WithMetadata added in v0.25.0

func WithMetadata(m map[string]string) MetadataOption

WithMetadata returns an option adding the given metadata.

func (MetadataOption) BeforeHandler added in v0.25.0

func (o MetadataOption) BeforeHandler(opts *options.HandlerOptions)

func (MetadataOption) BeforeServiceDefinition added in v0.25.0

func (o MetadataOption) BeforeServiceDefinition(opts *options.ServiceDefinitionOptions)

type RetryableError added in v0.25.0

type RetryableError interface {
	error
	// Code returns the status code attached to the error.
	Code() Code
	// Message returns the error message.
	Message() string
	// contains filtered or unexported methods
}

RetryableError finishes an attempt with a non-terminal failure: the invocation (or a Run function) is retried rather than completed. It carries a status code and a message, wraps the underlying error, and implements the error interface.

func AsRetryableError added in v0.25.0

func AsRetryableError(err error) RetryableError

AsRetryableError extracts the RetryableError from err if it is, or wraps, one; otherwise it returns nil.

func NewRetryableError added in v0.25.0

func NewRetryableError(err error, opts ...RetryableErrorOption) RetryableError

NewRetryableError wraps err as a RetryableError, defaulting the code to DefaultCode unless overridden by an option.

func ToRetryableError added in v0.25.0

func ToRetryableError(err error, opts ...RetryableErrorOption) RetryableError

ToRetryableError converts err into a RetryableError. It returns nil if err is nil; if err already is, or wraps, a RetryableError and no options are given it is returned unchanged; otherwise err is wrapped in a new RetryableError.

type RetryableErrorOption added in v0.25.0

type RetryableErrorOption interface {
	// contains filtered or unexported methods
}

RetryableErrorOption customizes a RetryableError at construction time.

type TerminalError

type TerminalError interface {
	error
	// Code returns the status code attached to the error.
	Code() Code
	// Message returns the error message.
	Message() string
	// Metadata returns the metadata attached to the error as a read-only view.
	Metadata() stringmap.Map
	// contains filtered or unexported methods
}

TerminalError finishes an invocation (or a Run function) with a failure result instead of being retried. It carries a status code, a message and optional metadata, and implements the error interface.

func AsTerminalError added in v0.25.0

func AsTerminalError(err error) TerminalError

AsTerminalError extracts the TerminalError from err if it is, or wraps, one; otherwise it returns nil.

func NewTerminalError

func NewTerminalError(message string, opts ...TerminalErrorOption) TerminalError

NewTerminalError builds a TerminalError with the given message, defaulting the code to DefaultCode unless overridden by an option.

func ToTerminalError added in v0.25.0

func ToTerminalError(err error, opts ...TerminalErrorOption) TerminalError

ToTerminalError converts err into a TerminalError. It returns nil if err is nil; if err already is, or wraps, a TerminalError and no options are given it is returned unchanged; otherwise a TerminalError is built from err.Error(). err is not wrapped - only its message is copied, a TerminalError carries no nested error.

type TerminalErrorOption added in v0.25.0

type TerminalErrorOption interface {
	// contains filtered or unexported methods
}

TerminalErrorOption customizes a TerminalError at construction time.

Jump to

Keyboard shortcuts

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