Documentation
¶
Index ¶
Constants ¶
const DefaultWrapWidth = 80
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DefaultHandler ¶
Handler handles errors providing colored output to a specified writer (defaults to stderr).
func NewDefaultHandler ¶
func NewDefaultHandler(output io.Writer) *DefaultHandler
NewDefaultHandler creates a new DefaultErrorHandler with the specified output writer. If no writer is provided, it defaults to stderr.
func (*DefaultHandler) HandleError ¶
func (h *DefaultHandler) HandleError(err error)
HandleError checks if the given error implements the ErrorWithHelp interface. If it does, it prints the error message and help message in a colored format to the configured output writer. Otherwise, it prints a generic error message.
func (*DefaultHandler) NewGeneralError ¶
func (h *DefaultHandler) NewGeneralError(message, helpMsg string, err error, code int) *GeneralError
func (*DefaultHandler) SetWrap ¶ added in v0.8.7
func (h *DefaultHandler) SetWrap(wrap bool)
func (*DefaultHandler) SetWrapWidth ¶ added in v0.8.7
func (h *DefaultHandler) SetWrapWidth(width int)
type ErrorWithHelp ¶
type ErrorWithHelp interface { error // Help returns a help message for the error Help() string // Unwrap returns the underlying error Unwrap() error // Optional: for wrapped errors // Code returns the error code Code() int // Optional: for error codes }
ErrorWithHelp interface is used for errors that can provide help
type GeneralError ¶
func (*GeneralError) Code ¶
func (e *GeneralError) Code() int
func (*GeneralError) Error ¶
func (e *GeneralError) Error() string
func (*GeneralError) Help ¶
func (e *GeneralError) Help() string
func (*GeneralError) Unwrap ¶
func (e *GeneralError) Unwrap() error
type Handler ¶
type Handler interface { // HandleError handles the given error. HandleError(err error) // NewGeneralError creates a new GeneralError with the specified message, help message, error, and code. NewGeneralError(message, helpMsg string, err error, code int) *GeneralError // SetWrap sets whether to wrap the error message and help message. SetWrap(wrap bool) // SetWrapWidth sets the width to wrap the error message and help message. SetWrapWidth(width int) }
Handler is an interface for handling errors.
type InvalidArgumentError ¶
type InvalidArgumentError struct { Flag string Val string OneOf []string SeeOther string Context string }
InvalidArgumentError is returned when an argument is invalid
func (*InvalidArgumentError) Code ¶
func (e *InvalidArgumentError) Code() int
func (*InvalidArgumentError) Error ¶
func (e *InvalidArgumentError) Error() string
func (*InvalidArgumentError) Help ¶
func (e *InvalidArgumentError) Help() string
Help returns the error message
func (*InvalidArgumentError) Unwrap ¶
func (e *InvalidArgumentError) Unwrap() error