errors

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2026 License: EUPL-1.2 Imports: 2 Imported by: 0

Documentation

Overview

Package errors provides structured error handling for Core applications.

Errors include operational context (what was being done) and support error wrapping for debugging while keeping user-facing messages clean:

err := errors.E("user.Create", "email already exists", nil)
err := errors.Wrap(dbErr, "user.Create", "failed to save user")

// Check error types
if errors.Is(err, sql.ErrNoRows) { ... }

// Extract operation
var e *errors.Error
if errors.As(err, &e) {
    fmt.Println("Operation:", e.Op)
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func As

func As(err error, target any) bool

As finds the first error in err's tree that matches target.

func Code

func Code(code, msg string) error

Code creates an error with just a code and message.

return errors.Code("ERR_VALIDATION", "invalid email format")

func E

func E(op, msg string, err error) error

E creates a new Error with operation context.

err := errors.E("config.Load", "file not found", os.ErrNotExist)
err := errors.E("api.Call", "rate limited", nil)

func ErrCode

func ErrCode(err error) string

ErrCode extracts the error code, or empty string if not set.

func Is

func Is(err, target error) bool

Is reports whether any error in err's tree matches target.

func Join

func Join(errs ...error) error

Join returns an error that wraps the given errors.

func Message

func Message(err error) string

Message extracts the message from an error. For Error types, returns Msg; otherwise returns err.Error().

func New

func New(text string) error

New returns an error with the given text.

func Op

func Op(err error) string

Op extracts the operation from an error, or empty string if not an Error.

func Root

func Root(err error) error

Root returns the deepest error in the chain.

func Wrap

func Wrap(err error, op, msg string) error

Wrap wraps an error with operation context. Returns nil if err is nil.

return errors.Wrap(err, "db.Query", "failed to fetch user")

func WrapCode

func WrapCode(err error, code, op, msg string) error

WrapCode wraps an error with operation context and an error code.

return errors.WrapCode(err, "ERR_NOT_FOUND", "user.Get", "user not found")

Types

type Error

type Error struct {
	Op   string // Operation being performed (e.g., "user.Create")
	Msg  string // Human-readable message
	Err  error  // Underlying error (optional)
	Code string // Error code for i18n/categorisation (optional)
}

Error represents a structured error with operational context.

func (*Error) Error

func (e *Error) Error() string

Error returns the error message.

func (*Error) Unwrap

func (e *Error) Unwrap() error

Unwrap returns the underlying error.

Jump to

Keyboard shortcuts

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