errs

package
v1.2.0 Latest Latest
Warning

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

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

Documentation

Overview

Package errs defines exit-code-aware typed errors for the CLI.

Commands return *Error values; cmd.Execute() inspects the code and exits with the matching numeric exit code per the mp2rss CLI contract:

0 success | 1 generic | 2 args | 3 auth | 4 not found | 5 upstream unavailable

Index

Constants

View Source
const (
	CodeOK           = 0
	CodeGeneric      = 1
	CodeArgs         = 2
	CodeAuth         = 3
	CodeNotFound     = 4
	CodeUpstreamDown = 5
)

Exit codes per the CLI contract.

Variables

This section is empty.

Functions

This section is empty.

Types

type Error

type Error struct {
	Code       int    // exit code
	HTTPStatus int    // upstream HTTP status if any
	Message    string // user-facing message
	Cause      error  // wrapped underlying error (for `errors.Is/As`)
}

Error is a CLI-visible error with both a human message and an exit code.

HTTPStatus is the upstream HTTP status code when the error originated from an API response. It is 0 for purely local errors.

func As

func As(err error) (*Error, bool)

As converts err to *Error. Returns (nil, false) for non-typed errors.

func Newf

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

Newf creates a typed CLI error.

func Wrap

func Wrap(code int, err error) *Error

Wrap turns any error into a CLI error with the given exit code.

func (*Error) Error

func (e *Error) Error() string

Error returns the message.

func (*Error) Unwrap

func (e *Error) Unwrap() error

Unwrap exposes the wrapped error.

Jump to

Keyboard shortcuts

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