errcode

package
v0.0.0-...-5ed4770 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package errcode provides structured error codes with HTTP status mapping.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrAuthFailed              = &predefined{code: 4001} // Reserved for developer SDK — Sequify Server does not perform auth
	ErrCredentialExpired       = &predefined{code: 4002} // Reserved for developer SDK — Sequify Server does not perform auth
	ErrConnLimit               = &predefined{code: 4003}
	ErrBadMessage              = &predefined{code: 4004}
	ErrCapabilityNotRegistered = &predefined{code: 4005}
	ErrVersionIncompat         = &predefined{code: 4006}
)

Connection-level errors (4xxx) — WebSocket connection lifecycle

View Source
var (
	ErrConvNotFound       = &predefined{code: 5001}
	ErrMsgNotFound        = &predefined{code: 5002}
	ErrIntentFailed       = &predefined{code: 5003}
	ErrToolTimeout        = &predefined{code: 5004}
	ErrConvDestroyed      = &predefined{code: 5005}
	ErrConcurrentConflict = &predefined{code: 5006}
	ErrCapabilityNotFound = &predefined{code: 5007}
)

Command-level errors (5xxx) — business logic failures

View Source
var (
	ErrInternal       = &predefined{code: 6001}
	ErrLLMUnavailable = &predefined{code: 6002}
	ErrQueueFull      = &predefined{code: 6003}
	ErrDB             = &predefined{code: 6004}
	ErrRedis          = &predefined{code: 6005}
)

Service-level errors (6xxx) — infrastructure failures

Functions

func HTTPStatus

func HTTPStatus(code int) int

HTTPStatus returns the HTTP status code for the given error code. Returns 500 for unknown codes.

This function queries the registry directly instead of maintaining a separate map, ensuring a single source of truth for HTTP status mappings.

func Register

func Register(code int, defaultMsg string, httpStatus int)

Register adds an error code to the global registry. It panics if the code is out of range [4000, 6999] or already registered.

func RegisterAll

func RegisterAll()

RegisterAll registers all error codes from protocol.md. Must be called once in main.go before using any predefined error variables. Safe to call multiple times (idempotent).

Types

type Error

type Error struct {
	Code       int
	Message    string
	HTTPStatus int
	// contains filtered or unexported fields
}

Error is a structured error type with code, message, and HTTP status.

func New

func New(code int) *Error

New creates a new Error with the default message from the registry. It panics if the code is not registered.

func Newf

func Newf(code int, format string, args ...any) *Error

Newf creates a new Error with a custom formatted message. It supports %w verb for wrapping sentinel errors. It panics if the code is not registered.

func (*Error) Error

func (e *Error) Error() string

Error returns the string representation in [code] message format.

func (*Error) Is

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

Is reports whether target is an *Error with the same code.

func (*Error) Unwrap

func (e *Error) Unwrap() error

Unwrap returns the wrapped error, if any.

Jump to

Keyboard shortcuts

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