errors

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2026 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package errors provides structured error types for tcount.

Index

Constants

View Source
const (
	ErrCodeNotFound   = "NOT_FOUND"
	ErrCodeValidation = "VALIDATION"
	ErrCodeIO         = "IO"
	ErrCodeParse      = "PARSE"
	ErrCodeInternal   = "INTERNAL"
)

Error codes for categorization.

Variables

This section is empty.

Functions

func Code

func Code(err error) string

Code extracts the error code from any error.

Types

type Error

type Error struct {
	Code    string
	Message string
	Op      string
	Err     error
	Fields  map[string]any
	Hint    string
}

Error is a structured error type with code, context, and chain support.

func IO

func IO(op string, err error) *Error

IO creates an IO error.

func New

func New(message string) *Error

New creates a new error with a message.

func NotFound

func NotFound(resource string) *Error

NotFound creates a NOT_FOUND error.

func Parse

func Parse(message string, err error) *Error

Parse creates a PARSE error.

func Validation

func Validation(message string) *Error

Validation creates a VALIDATION error.

func Wrap

func Wrap(err error, message string) *Error

Wrap wraps an existing error with a message.

func (*Error) Error

func (e *Error) Error() string

Error returns the error string with context.

func (*Error) Unwrap

func (e *Error) Unwrap() error

Unwrap returns the wrapped error.

func (*Error) WithCode

func (e *Error) WithCode(code string) *Error

WithCode sets the error code.

func (*Error) WithField

func (e *Error) WithField(key string, value any) *Error

WithField adds a context field.

func (*Error) WithHint

func (e *Error) WithHint(hint string) *Error

WithHint adds an actionable suggestion to the error.

Jump to

Keyboard shortcuts

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