errs

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2025 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Code

type Code string

Code represents canonical error codes for MCP operations

const (
	// INVALID_ARGUMENT indicates client-provided argument is invalid
	CodeInvalidArgument Code = "INVALID_ARGUMENT"

	// NOT_FOUND indicates requested resource was not found
	CodeNotFound Code = "NOT_FOUND"

	// ALREADY_EXISTS indicates resource already exists
	CodeAlreadyExists Code = "ALREADY_EXISTS"

	// PERMISSION_DENIED indicates client lacks permission
	CodePermissionDenied Code = "PERMISSION_DENIED"

	// UNAUTHENTICATED indicates client authentication failed
	CodeUnauthenticated Code = "UNAUTHENTICATED"

	// FAILED_PRECONDITION indicates operation precondition not met
	CodeFailedPrecondition Code = "FAILED_PRECONDITION"

	// INTERNAL indicates server internal error
	CodeInternal Code = "INTERNAL"

	// UNAVAILABLE indicates service temporarily unavailable
	CodeUnavailable Code = "UNAVAILABLE"

	// UNSUPPORTED indicates operation not supported
	CodeUnsupported Code = "UNSUPPORTED"

	// CONFLICT indicates resource conflict
	CodeConflict Code = "CONFLICT"
)

func (Code) String

func (c Code) String() string

String returns the string representation of the code

type Error

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

Error represents a typed error with code, message, and optional key-value context

func AlreadyExists

func AlreadyExists(resource string, kv ...interface{}) *Error

AlreadyExists creates an ALREADY_EXISTS error with optional key-value context

func FailedPrecondition

func FailedPrecondition(msg string, kv ...interface{}) *Error

FailedPrecondition creates a FAILED_PRECONDITION error with optional key-value context

func Internal

func Internal(err error, kv ...interface{}) *Error

Internal creates an INTERNAL error, optionally wrapping another error, with key-value context

func InvalidArg

func InvalidArg(msg string, kv ...interface{}) *Error

InvalidArg creates an INVALID_ARGUMENT error with optional key-value context

func New

func New(code Code, message string, cause error, kv ...interface{}) *Error

New creates a new typed error with the given code, message, cause, and key-value context

func NotFound

func NotFound(resource string, kv ...interface{}) *Error

NotFound creates a NOT_FOUND error for a specific resource with optional key-value context

func Unsupported

func Unsupported(msg string, kv ...interface{}) *Error

Unsupported creates an UNSUPPORTED error with optional key-value context

func Wrap

func Wrap(code Code, err error, kv ...interface{}) *Error

Wrap creates an error with the specified code, wrapping another error, with key-value context

func (*Error) As

func (e *Error) As(target interface{}) bool

As implements error casting for Go 1.13+ error handling

func (*Error) Cause

func (e *Error) Cause() error

Cause returns the underlying cause error, if any

func (*Error) Code

func (e *Error) Code() Code

Code returns the error code

func (*Error) Error

func (e *Error) Error() string

Error implements the error interface with JSON-safe output for backwards compatibility

func (*Error) Is

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

Is implements error comparison for Go 1.13+ error handling

func (*Error) KV

func (e *Error) KV() map[string]interface{}

KV returns the key-value context

func (*Error) Message

func (e *Error) Message() string

Message returns the error message

func (*Error) Unwrap

func (e *Error) Unwrap() error

Unwrap implements error unwrapping for Go 1.13+ error handling

type MCPErrorCode

type MCPErrorCode int

MCPErrorCode represents MCP protocol error codes

const (
	// MCP protocol error codes based on JSON-RPC 2.0 spec
	MCPErrorInvalidRequest MCPErrorCode = -32600
	MCPErrorMethodNotFound MCPErrorCode = -32601
	MCPErrorInvalidParams  MCPErrorCode = -32602
	MCPErrorInternalError  MCPErrorCode = -32603
	MCPErrorParseError     MCPErrorCode = -32700

	// MCP-specific error codes
	MCPErrorNotFound         MCPErrorCode = -32001
	MCPErrorConflict         MCPErrorCode = -32002
	MCPErrorUnavailable      MCPErrorCode = -32003
	MCPErrorUnsupported      MCPErrorCode = -32004
	MCPErrorPermissionDenied MCPErrorCode = -32005
	MCPErrorUnauthenticated  MCPErrorCode = -32006
)

func ToMCPError

func ToMCPError(err error) (MCPErrorCode, string)

ToMCPError translates a typed error to MCP error code and message

Jump to

Keyboard shortcuts

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