errors

package
v1.10.7 Latest Latest
Warning

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

Go to latest
Published: May 5, 2026 License: MIT Imports: 2 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package errors defines a typed error taxonomy for Helix's MCP tools.

Import convention: use alias "serr" to avoid shadowing stdlib errors.

import serr "github.com/agenthands/helix/internal/errors"

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound    = &Error{Kind: NotFound}
	ErrInvalidArgs = &Error{Kind: InvalidArgs}
	ErrNoWorkspace = &Error{Kind: NoWorkspace}
	ErrUnsupported = &Error{Kind: Unsupported}
	ErrInternal    = &Error{Kind: Internal}
	ErrCircuitOpen = &Error{Kind: CircuitOpen}
	ErrTimeout     = &Error{Kind: Timeout}
)

Sentinel errors for use with errors.Is. Each sentinel carries only a Kind; Error.Is() compares Kind values, so errors.Is(err, ErrNotFound) matches any *Error with Kind == NotFound.

Functions

This section is empty.

Types

type Error

type Error struct {
	Kind    Kind   `json:"kind"`
	Message string `json:"message"`
	Tool    string `json:"tool,omitempty"`
	Detail  string `json:"detail,omitempty"`
	// contains filtered or unexported fields
}

Error is the structured error type for all Helix MCP tools. It carries a Kind for programmatic matching, a human-readable Message, an optional Tool name, an optional Detail string, and an unexported cause for error chain traversal.

CRITICAL: Functions returning the error interface must never assign a *Error nil pointer to a variable and return it. Always return nil directly. A typed nil *Error satisfies error as non-nil, causing false positives.

func New

func New(kind Kind, message string) *Error

New creates a typed error with the given Kind and message.

func Wrap

func Wrap(kind Kind, message string, cause error) *Error

Wrap creates a typed error that wraps a cause error, preserving the error chain for errors.Is and errors.As traversal.

func (*Error) Error

func (e *Error) Error() string

Error returns a human-readable string: "kind: message" or "kind: message (detail)" when Detail is non-empty.

func (*Error) Is

func (e *Error) Is(target error) bool

Is enables errors.Is matching by Kind. When the target is an *Error, it matches if both errors share the same Kind value. This allows sentinel-based matching: errors.Is(err, serr.ErrNotFound).

func (*Error) MarshalJSON

func (e *Error) MarshalJSON() ([]byte, error)

MarshalJSON returns the JSON encoding of the Error. Uses a type alias to prevent infinite recursion through the json.Marshaler interface.

func (*Error) Unwrap

func (e *Error) Unwrap() error

Unwrap returns the underlying cause error for error chain traversal.

func (*Error) WithDetail

func (e *Error) WithDetail(detail string) *Error

WithDetail sets the detail string on the error and returns the same *Error for builder-style chaining.

func (*Error) WithTool

func (e *Error) WithTool(tool string) *Error

WithTool sets the tool name on the error and returns the same *Error for builder-style chaining.

type Kind

type Kind string

Kind classifies errors for programmatic matching by agents. Callers check Kind via errors.Is(err, serr.ErrNotFound) rather than string matching on error messages.

const (
	NotFound    Kind = "not_found"
	InvalidArgs Kind = "invalid_args"
	NoWorkspace Kind = "no_workspace"
	Unsupported Kind = "unsupported"
	Internal    Kind = "internal"
	CircuitOpen Kind = "circuit_open"
	Timeout     Kind = "timeout"
)

Jump to

Keyboard shortcuts

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