Documentation
¶
Index ¶
- Variables
- func Chain(err error) error
- func ChainWith(err error, message string) error
- func ChainWithf(err error, format string, args ...interface{}) error
- func Configure(opts ...ReportOption)
- func Flatten(err error) error
- func HitFan(err error, opts ...ReportOption)
- func IterChain(err error) iter.Seq[error]
- func New(message string) error
- func NewDefaultReporter(opts ...DefaultReporterOption) func(w io.Writer, err error) error
- func Newf(format string, args ...interface{}) error
- func OmitImportPath(f string) string
- func PathBase(path string) string
- func PathLastNSegments(n int) func(path string) string
- func WithColor(c color.Attribute) func(string) string
- type ChainedError
- type DefaultReporterOption
- type DefaultReporterOptions
- type FormattedValue
- type Frame
- type FuncFormatter
- type PathFormatter
- type ReportOption
- type ReportOptions
- type Reporter
- type SHTF
Constants ¶
This section is empty.
Variables ¶
var DefaultReporter = NewDefaultReporter()
DefaultReporter is the default reporter that is used when no reporter is provided.
Functions ¶
func Chain ¶
Chain chains the given error. This is the most common way to chain. It captures the caller information, the location where this error is being returned, but doesn't require any other information.
func ChainWithf ¶
ChainWithf is identical to ChainWith, but allows formatted messages.
func Configure ¶
func Configure(opts ...ReportOption)
Configure modifies the default reporting options changing the global default behavior of HitFan. This is intended for 1-time configuration in main.
func Flatten ¶
Flatten flattens the chain into a single error with the information about the chain in the error message. This is useful in contexts where you need to capture everyting in the string returned via Error, like zap logging, zap.Error(poop.Flatten(err)).
func HitFan ¶
func HitFan(err error, opts ...ReportOption)
HitFan reports the given error and then terminates the program using the report options to control how the error is reported and the mechanism by which the program is terminated.
func IterChain ¶
IterChain is an iterator of all the errors in the chain.
TODO(kellegous): Since ChainError is not exported, this should be changed to a method on ChainedError.
func New ¶
New creates a leaf error with caller information. This is the poop equivalent to `errors.New`.
func NewDefaultReporter ¶
func NewDefaultReporter(opts ...DefaultReporterOption) func(w io.Writer, err error) error
NewDefaultReporter creates a new default reporter with the given options.
func OmitImportPath ¶
OmitImportPath returns the last segment of the given function name.
func PathLastNSegments ¶
PathLastNSegments returns a function that returns the last n segments of the given path.
Types ¶
type ChainedError ¶
type ChainedError struct {
// contains filtered or unexported fields
}
ChainedError represents a link in the causal chain of errors.
func (*ChainedError) Error ¶
func (e *ChainedError) Error() string
func (*ChainedError) Frame ¶
func (e *ChainedError) Frame() Frame
Frame returns the frame information for the caller of the error. This will be the call frame for the chain link.
func (*ChainedError) Message ¶
func (e *ChainedError) Message() string
Message returns the message that was provided when the error was chained. The message is optional and may be empty.
func (*ChainedError) RootCause ¶
func (e *ChainedError) RootCause() error
RootCause returns the first error in the chain.
func (*ChainedError) Unwrap ¶
func (e *ChainedError) Unwrap() error
type DefaultReporterOption ¶
type DefaultReporterOption func(*DefaultReporterOptions)
DefaultReporterOption is a function that modifies the default reporter options.
func WithFuncFormatter ¶
func WithFuncFormatter(formatter FuncFormatter) DefaultReporterOption
WithFuncFormatter sets the function formatter for the default reporter.
func WithPathFormatter ¶
func WithPathFormatter(formatter PathFormatter) DefaultReporterOption
WithPathFormatter sets the path formatter for the default reporter.
type DefaultReporterOptions ¶
type DefaultReporterOptions struct {
// contains filtered or unexported fields
}
DefaultReporterOptions is the options for the default reporter.
type FormattedValue ¶
type FuncFormatter ¶
type FuncFormatter func(function string) FormattedValue
FuncFormatter formats a function name into a formatted value.
func NewFuncFormatter ¶
func NewFuncFormatter( stringFn func(string) string, colorFn func(string) string, ) FuncFormatter
NewFuncFormatter creates a new FuncFormatter that formats a function name into a formatted value.
type PathFormatter ¶
type PathFormatter func(path string, line int) FormattedValue
PathFormatter formats a path and line number into a formatted value.
type ReportOption ¶
type ReportOption func(*ReportOptions)
func ExitWithStatus ¶
func ExitWithStatus(status int) ReportOption
func Panic ¶
func Panic() ReportOption
func UsingReporter ¶
func UsingReporter(reporter Reporter) ReportOption
type ReportOptions ¶
type ReportOptions struct {
// contains filtered or unexported fields
}
type SHTF ¶
type SHTF interface {
HitFan(err error)
}
func BeReady ¶
func BeReady(opts ...ReportOption) SHTF
BeReady creates a new SHTF instance with the given options. This allows for the creation of customized reporting behavior in a specific area of code, without affecting the global default behavior.
