errors

package
v1.3.4 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2026 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Overview

Package errors provides standardized error types for use across PromptKit modules.

ContextualError is the base error type that captures component, operation, and optional status code and details. It implements the error and Unwrap interfaces for seamless integration with Go's errors package.

Usage:

err := errors.New("sdk", "OpenConversation", someErr)
err = err.WithStatusCode(404).WithDetails(map[string]any{"pack": "my-pack"})

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ContextualError

type ContextualError struct {
	// Component identifies the module that produced the error (e.g. "sdk", "runtime", "arena").
	Component string

	// Operation describes what was being done when the error occurred.
	Operation string

	// StatusCode is an optional HTTP or application-level status code.
	StatusCode int

	// Details holds optional structured metadata about the error.
	Details map[string]any

	// Cause is the underlying error, if any.
	Cause error
}

ContextualError is a structured error type that provides consistent context about where and why an error occurred across PromptKit modules.

func New

func New(component, operation string, cause error) *ContextualError

New creates a ContextualError with the given component, operation, and cause.

func (*ContextualError) Error

func (e *ContextualError) Error() string

Error returns a human-readable representation of the error.

func (*ContextualError) Unwrap

func (e *ContextualError) Unwrap() error

Unwrap returns the underlying cause, enabling use with errors.Is and errors.As.

func (*ContextualError) WithDetails

func (e *ContextualError) WithDetails(details map[string]any) *ContextualError

WithDetails returns a copy of the error with the given details map set.

func (*ContextualError) WithStatusCode

func (e *ContextualError) WithStatusCode(code int) *ContextualError

WithStatusCode returns a copy of the error with the given status code set.

Jump to

Keyboard shortcuts

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