Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ErrIgnore = errors.New("error can be ignored")
var ErrorHandlers = []func(error){ func() func(err error) { limiter := rate.NewLimiter(rate.Every(time.Millisecond), 1) return func(err error) { _ = limiter.Wait(context.Background()) } }(), }
ErrorHandlers is a list of functions which will be invoked when a nonreturnable error occurs. should be packaged up into a testable and reusable object.
Functions ¶
func HandleError ¶
func HandleError(err error)
HandleError is a method to invoke when a non-user facing piece of code cannot return an error and needs to indicate it has been ignored. Invoking this method is preferable to logging the error - the default behavior is to log but the errors may be sent to a remote server for analysis.
func Mark ¶
Mark returns an error with the supplied errors as marks. If err is nil, return nil. marks take effects only when Is and '%v' in fmt. Is returns true if err or any marks match the target.
Example ¶
package main import ( "fmt" errors_ "github.com/searKing/golang/go/errors" ) func main() { err := errors_.Mark(nil, nil) fmt.Println(err) fmt.Println("-----") err = errors_.Mark(fmt.Errorf("whoops"), nil) fmt.Println(err) fmt.Println("-----") err = errors_.Mark(fmt.Errorf("whoops"), fmt.Errorf("foo")) fmt.Println(err) fmt.Println("-----") err = errors_.Mark(fmt.Errorf("whoops"), fmt.Errorf("foo"), fmt.Errorf("bar")) fmt.Println(err) fmt.Println("-----") err = errors_.Mark(err, fmt.Errorf("alice"), fmt.Errorf("bob")) fmt.Println(err) fmt.Println("-----") }
Output: <nil> ----- whoops ----- whoops ----- whoops ----- whoops -----
func Multi ¶
Multi returns an error with the supplied errors. If no error contained, return nil.
Example ¶
package main import ( "fmt" errors_ "github.com/searKing/golang/go/errors" ) func main() { err := errors_.Multi(nil, nil) fmt.Println(err) fmt.Println("-----") err = errors_.Multi(fmt.Errorf("whoops"), nil) fmt.Println(err) fmt.Println("-----") err = errors_.Multi(fmt.Errorf("whoops"), fmt.Errorf("foo")) fmt.Println(err) fmt.Println("-----") }
Output: <nil> ----- whoops ----- whoops|foo -----
Types ¶
This section is empty.