errors

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package errors provides typed errors carrying a semantic exit code. Every command handler returns plain error; main.go uses CodeOf to translate to the global exit code table when calling os.Exit.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HintOf

func HintOf(err error) string

HintOf returns the hint of the first *Error in the chain, or "" if none.

Types

type Error

type Error struct {
	Code    ExitCode
	Message string
	Hint    string
	Cause   error
}

Error carries a semantic exit code, a user-facing message, an optional next-step hint, and an optional wrapped cause.

func New

func New(code ExitCode, msg string) *Error

New constructs a lore error with no underlying cause.

func Newf

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

Newf is New with fmt.Sprintf formatting.

func Wrap

func Wrap(code ExitCode, cause error, msg string) *Error

Wrap attaches a cause to a new lore error.

func (*Error) Error

func (e *Error) Error() string

func (*Error) Unwrap

func (e *Error) Unwrap() error

func (*Error) WithHint

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

WithHint returns err with its next-step hint set. Chains naturally with constructors: errors.New(...).WithHint("...").

type ExitCode

type ExitCode int

ExitCode is the process exit code class for a lore error. The same code means the same class of failure across every subcommand so scripts and agents can react uniformly. The exact cause goes in the error Message.

const (
	CodeSuccess       ExitCode = 0
	CodeGenericError  ExitCode = 1
	CodeSetupMissing  ExitCode = 2
	CodeNotFound      ExitCode = 3
	CodeConflict      ExitCode = 4
	CodeRefusedSafety ExitCode = 5
	CodeGitNetwork    ExitCode = 6
	CodeInconsistency ExitCode = 7
)

func CodeOf

func CodeOf(err error) ExitCode

CodeOf walks the error chain and returns the first ExitCode found, or CodeGenericError if no *Error appears in the chain. Returns CodeSuccess only when err is nil.

Jump to

Keyboard shortcuts

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