errors

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package errors provides a simplified, production-ready error handling system.

Index

Constants

View Source
const (
	ExitSuccess         = 0
	ExitGeneralError    = 1
	ExitUsageError      = 2
	ExitValidationError = 3
	ExitConfigError     = 4
	ExitRuntimeError    = 5
)

Exit codes for different error scenarios.

Variables

This section is empty.

Functions

func GetExitCode

func GetExitCode(err error) int

GetExitCode extracts the exit code from any error.

func Wrap

func Wrap(err error, message string) error

Wrap adds a simple message context to any error.

Types

type BaseError

type BaseError struct {
	Message     string   // What went wrong
	Component   string   // Where it happened (e.g., "pipeline", "command", "attestor")
	Operation   string   // What was being done (e.g., "validate", "execute", "sign")
	Cause       error    // Underlying error if any
	Suggestions []string // User-friendly suggestions (only shown in human output)
	ExitCode    int      // CLI exit code
}

BaseError is our standard error with structured context.

func New

func New(message string) *BaseError

New creates a basic error.

func NewUsageError

func NewUsageError(message string, suggestions ...string) *BaseError

NewUsageError creates a usage error with suggestions.

func NewWithContext

func NewWithContext(component, operation, message string) *BaseError

NewWithContext creates an error with context.

func WrapAttestor

func WrapAttestor(err error, attestorID, phase string) *BaseError

WrapAttestor wraps an error with attestor context.

func WrapPipeline

func WrapPipeline(err error, phase, attestorID string) *BaseError

WrapPipeline wraps an error with pipeline context.

func WrapWithContext

func WrapWithContext(err error, component, operation, message string) *BaseError

WrapWithContext adds component/operation context to an error.

func (*BaseError) Error

func (e *BaseError) Error() string

Error implements the error interface.

func (*BaseError) Suggest

func (e *BaseError) Suggest(suggestions ...string) *BaseError

Suggest adds user-friendly suggestions to an error.

func (*BaseError) Unwrap

func (e *BaseError) Unwrap() error

Unwrap returns the underlying error for errors.Is/As support.

func (*BaseError) WithExitCode

func (e *BaseError) WithExitCode(code int) *BaseError

WithExitCode sets the exit code.

type ValidationError

type ValidationError struct {
	BaseError
	Fields map[string][]string // field -> list of error messages
}

ValidationError aggregates field-level validation issues.

func NewValidator

func NewValidator() *ValidationError

NewValidator creates a validation error collector.

func NewValidatorFor

func NewValidatorFor(component string) *ValidationError

NewValidatorFor creates a validation error collector for a specific component.

func (*ValidationError) AddError

func (v *ValidationError) AddError(field, message string)

AddError adds a field validation error.

func (*ValidationError) Error

func (v *ValidationError) Error() string

Error returns the formatted error message.

func (*ValidationError) HasErrors

func (v *ValidationError) HasErrors() bool

HasErrors checks if there are any validation errors.

Jump to

Keyboard shortcuts

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