clierr

package
v1.2.3 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2023 License: MIT Imports: 1 Imported by: 38

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Err

type Err struct {
	// Err is a string to avoid punctuation linting
	Err string
	// setting ExcludeDefaultError to true will cause the PrintCLIError method to only print the contents of Messages
	// by default PrintCLIError first prints the contents of Err, followed by the contents of Messages
	ExcludeDefaultError bool
	// Messages are items which implement the clio.Printer interface.
	// when PrintCLIError is called, each of the messages Print() method is called in order of appearence in the slice
	Messages []Printer
}

Err is a CLI error. Calling PrintCLIError() on it will print error messages to the console.

func New

func New(err string, msgs ...Printer) *Err

New creates a new CLI error. You can append additional log messages to the error by adding fields to the 'msgs' argument.

Example:

clierr.New("something bad happened", clierr.Error("some extra context here"))

func (*Err) Error

func (e *Err) Error() string

Error implements the error interface. It uses the default message of the wrapped error.

func (*Err) PrintCLIError

func (e *Err) PrintCLIError()

PrintCLIError prints the error message and then any messages in order from the slice The indended use is to surface errors with useful messages then os.Exit without having to place os.Exit within methods other than the cli main function

err := CLIError{Err: "new error", Messages: []Printer{Log("hello world")}}

err.PrintCLIError()
// produces
[✘] new error
hello world

type Msg

type Msg struct {
	Format string
	Args   []any
	// contains filtered or unexported fields
}

func Debug

func Debug(args ...any) Msg

Debug adds a debug message. This message will only be displayed if the logging level is set to 'debug'.

func Debugf

func Debugf(format string, a ...any) Msg

Debugf adds a formatted debug message. This message will only be displayed if the logging level is set to 'debug'.

func Error

func Error(args ...any) Msg

Error adds a error message.

func Errorf

func Errorf(format string, a ...any) Msg

Errorf adds a formatted error message.

func Info

func Info(args ...any) Msg

Info adds an info message.

func Infof

func Infof(format string, a ...any) Msg

Infof adds a formatted info message.

func Log

func Log(args ...any) Msg

Log adds a log message. Warning: this will be printed to stdout, rather than stderr.

func Logf

func Logf(format string, a ...any) Msg

Logf adds a formatted log message. Warning: this will be printed to stdout, rather than stderr.

func Success

func Success(args ...any) Msg

Success adds a success message.

func Successf

func Successf(format string, a ...any) Msg

Successf adds a formatted success message.

func Warn

func Warn(args ...any) Msg

Warn adds a warning message.

func Warnf

func Warnf(format string, a ...any) Msg

Warnf adds a formatted warning message.

func (Msg) Print

func (m Msg) Print()

type PrintCLIErrorer

type PrintCLIErrorer interface {
	PrintCLIError()
}

type Printer

type Printer interface {
	Print()
}

Jump to

Keyboard shortcuts

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