Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ExtendableFactory ¶ added in v0.7.0
type ExtendableFactory[T any] interface { Factory[T] Extend(f Factory[T]) ExtendableFactory[T] }
ExtendableFactory is an error factory that can be extended.
func NewM ¶ added in v0.6.0
func NewM(errFmt string) ExtendableFactory[M]
NewM returns a new ExtendableFactory instance using a template that expects a falta.M (i.e., map[string]any). This is a convenience function for calling falta.New[falta.M](...)
func Newf ¶
func Newf(errFmt string) ExtendableFactory[any]
Newf creates a new Falta instance that will construct errors using the printf format string provided.
type Factory ¶
Factory is an error factory.
Example ¶
package main import ( "fmt" "github.com/a20r/falta" ) type Circle struct { Radius float64 } var ErrInvalidCircle = falta.New[Circle]("invalid circle: radius ({{.Radius}}) <= 0") func IsCircleValid(circle Circle) error { if circle.Radius <= 0 { return ErrInvalidCircle.New(circle) } return nil } func main() { circle := Circle{Radius: -1} if err := IsCircleValid(circle); err != nil { fmt.Println(err) } }
Output: invalid circle: radius (-1) <= 0
type Falta ¶
type Falta struct {
// contains filtered or unexported fields
}
Falta is an error returned by the Factory
func NewError ¶ added in v0.5.0
NewError returns a new Falta error type with the provided error string.
NOTE (a20r, 2024-02-25): It panics if the provided message contains any fmt verbs.
func (Falta) Annotate ¶ added in v0.2.0
Annotate adds an annotation to the error to provide more context to why it's happening
NOTE (a20r, 2024-02-25): It panics if the provided annotation contains any fmt verbs.
func (Falta) Capture ¶ added in v0.4.0
Capture captures the error provided and wraps it with the Falta instance if it's not nil. This should be called with defer at the top of the function for which you are trying to capture the error. This ensures that all errors returned from your function will be wrapped by the function passed into Capture. You should use a named return value for the error so that the error Capture wraps is the one returned from teh function.
func (Falta) Is ¶ added in v0.1.0
Is returns true if the error provided is a Falta instance created by the same factory.