Documentation
¶
Index ¶
- Constants
- Variables
- func NewAssertionFailure(format string, args ...any) error
- func NewErrNotImplemented(issueURL string) error
- func WithUserHint(err error, hint string) error
- func WithUserHintf(err error, format string, args ...any) error
- func WrapWithHint(err error, msg string, hint string) error
- type ErrorHandler
- type ExitFunc
- type HelpConfig
- type Option
- type SlackHelp
- type StandardErrorHandler
- func (h *StandardErrorHandler) Check(err error, prefix string, level string, cmd ...*cobra.Command)
- func (h *StandardErrorHandler) Error(err error, prefixes ...string)
- func (h *StandardErrorHandler) Fatal(err error, prefixes ...string)
- func (h *StandardErrorHandler) SetUsage(usage func() error)
- func (h *StandardErrorHandler) Warn(err error, prefixes ...string)
- type TeamsHelp
Constants ¶
const ( LevelFatal = "fatal" LevelError = "error" LevelWarn = "warn" KeyStacktrace = "stacktrace" KeyHelp = "help" KeyHints = "hints" KeyDetails = "details" )
Variables ¶
var ( ErrNotImplemented = errors.New("command not yet implemented") ErrRunSubCommand = errors.New("subcommand required") )
Functions ¶
func NewAssertionFailure ¶
NewAssertionFailure creates an error denoting a programming bug.
func NewErrNotImplemented ¶
NewErrNotImplemented creates an unimplemented error with an optional issue tracker link.
func WithUserHint ¶
WithUserHint attaches a user-facing recovery suggestion to an error.
func WithUserHintf ¶
WithUserHintf attaches a formatted user-facing recovery suggestion.
Types ¶
type ErrorHandler ¶
type ErrorHandler interface {
Check(err error, prefix string, level string, cmd ...*cobra.Command)
Fatal(err error, prefixes ...string)
Error(err error, prefixes ...string)
Warn(err error, prefixes ...string)
SetUsage(usage func() error)
}
func New ¶
func New(logger *log.Logger, help HelpConfig, opts ...Option) ErrorHandler
type HelpConfig ¶
type HelpConfig interface {
SupportMessage() string
}
HelpConfig is the interface for providing contextual support information when errors occur. Implementations return a human-readable message directing users to a support channel. Returning an empty string suppresses the help output.
type Option ¶
type Option func(*StandardErrorHandler)
func WithExitFunc ¶
WithExitFunc allows injection of a custom exit handler (e.g. for testing).
func WithWriter ¶
WithWriter allows injection of a custom output writer.
type SlackHelp ¶
type SlackHelp struct {
Team string `json:"team" yaml:"team"`
Channel string `json:"channel" yaml:"channel"`
}
SlackHelp provides Slack channel contact details as a support message.
func (SlackHelp) SupportMessage ¶
type StandardErrorHandler ¶
type StandardErrorHandler struct {
Logger *log.Logger
Help HelpConfig
Exit ExitFunc
Writer io.Writer
Usage func() error
}
func (*StandardErrorHandler) Error ¶
func (h *StandardErrorHandler) Error(err error, prefixes ...string)
func (*StandardErrorHandler) Fatal ¶
func (h *StandardErrorHandler) Fatal(err error, prefixes ...string)
func (*StandardErrorHandler) SetUsage ¶
func (h *StandardErrorHandler) SetUsage(usage func() error)
func (*StandardErrorHandler) Warn ¶
func (h *StandardErrorHandler) Warn(err error, prefixes ...string)