toolerrors

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package toolerrors provides structured error types for tool invocation failures. ToolError preserves error chains and supports errors.Is/As while maintaining serialization compatibility for agent-as-tool scenarios.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ToolError

type ToolError struct {
	// Message is the human-readable summary of the failure.
	Message string
	// Cause links to the underlying tool error, enabling error chains with errors.Is/As.
	Cause *ToolError
}

ToolError represents a structured tool failure that preserves message and causal context while still implementing the standard error interface. Tool errors may be nested via Cause to retain rich diagnostics across retries and agent-as-tool hops.

func Errorf

func Errorf(format string, args ...any) *ToolError

Errorf formats according to a format specifier and returns the string as a ToolError.

func FromError

func FromError(err error) *ToolError

FromError converts an arbitrary error into a ToolError chain.

func New

func New(message string) *ToolError

New constructs a ToolError with the provided message. Use when the failure does not wrap an underlying error but still requires structured reporting.

func NewWithCause

func NewWithCause(message string, cause error) *ToolError

NewWithCause constructs a ToolError that wraps an underlying error. The cause is converted into a ToolError chain so error metadata survives serialization while still supporting errors.Is/As through Unwrap.

func (*ToolError) Error

func (e *ToolError) Error() string

Error implements the error interface.

func (*ToolError) Unwrap

func (e *ToolError) Unwrap() error

Unwrap returns the underlying tool error to support errors.Is/As.

Jump to

Keyboard shortcuts

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