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 sets the details map on this error and returns it for chaining.
func (*ContextualError) WithStatusCode ¶
func (e *ContextualError) WithStatusCode(code int) *ContextualError
WithStatusCode sets the status code on this error and returns it for chaining.