errors

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ErrCodeParseError indicates a JSON parse error (-32700).
	ErrCodeParseError = -32700
	// ErrCodeInvalidRequest indicates an invalid JSON-RPC request (-32600).
	ErrCodeInvalidRequest = -32600
	// ErrCodeMethodNotFound indicates the requested method was not found (-32601).
	ErrCodeMethodNotFound = -32601
	// ErrCodeInvalidParams indicates invalid method parameters (-32602).
	ErrCodeInvalidParams = -32602
	// ErrCodeInternalError indicates an internal server error (-32603).
	ErrCodeInternalError = -32603
	// ErrCodeServerError indicates a generic server error (-32000).
	ErrCodeServerError = -32000
	// ErrCodeTimeout indicates the request timed out (-32001).
	ErrCodeTimeout = -32001
	// ErrCodeUnauthorized indicates the request was unauthorized (-32604).
	ErrCodeUnauthorized = -32604
	// ErrCodeBudgetExceeded indicates the budget has been exceeded (-32050).
	ErrCodeBudgetExceeded = -32050
)

Variables

View Source
var (
	// ErrCodeContextNil indicates a nil context was provided.
	ErrCodeContextNil = -32010
	// ErrCodeContextTimeout indicates the context deadline exceeded limits.
	ErrCodeContextTimeout = -32011
	// ErrCodeContextCancel indicates the context was canceled.
	ErrCodeContextCancel = -32012

	// DefaultMinTimeout is the minimum allowed context timeout duration.
	DefaultMinTimeout = 100 * time.Millisecond
	// DefaultMaxTimeout is the maximum allowed context timeout duration.
	DefaultMaxTimeout = 5 * time.Minute
)

Functions

func ValidateContext

func ValidateContext(ctx context.Context) error

ValidateContext checks that the context is not nil, not already done, and its deadline falls within the allowed timeout range.

Types

type ContextError

type ContextError struct {
	Code    int
	Message string
	Cause   error
}

ContextError represents an error related to context validation failures.

func NewContextError

func NewContextError(code int, message string) *ContextError

NewContextError creates a new ContextError with the given error code and message.

func (*ContextError) Error

func (e *ContextError) Error() string

Error returns a formatted string of the context error including its code, message, and cause.

func (*ContextError) Unwrap

func (e *ContextError) Unwrap() error

Unwrap returns the underlying cause of the context error.

func (*ContextError) WithCause

func (e *ContextError) WithCause(cause error) *ContextError

WithCause attaches an underlying cause to the context error and returns the receiver.

type JSONRPCError

type JSONRPCError struct {
	Code    int             `json:"code"`
	Message string          `json:"message"`
	Data    json.RawMessage `json:"data,omitempty"`
}

JSONRPCError represents a JSON-RPC error response with code, message, and optional data.

func NewJSONRPCError

func NewJSONRPCError(code int, message string) *JSONRPCError

NewJSONRPCError creates a new JSONRPCError with the given error code and message.

func (*JSONRPCError) Error

func (e *JSONRPCError) Error() string

Error returns a formatted string describing the JSON-RPC error.

Jump to

Keyboard shortcuts

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