Documentation
¶
Index ¶
- func HasType(err error, referenceType error) bool
- func If(err error, pred func(err error) (interface{}, bool)) (interface{}, bool)
- func Is(err, reference error) bool
- func IsAny(err error, references ...error) bool
- func IsInterface(err error, referenceInterface interface{}) bool
- func IsType(err error, referenceType error) bool
- func Mark(err error, reference error) error
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func HasType ¶ added in v1.4.0
HasType returns true iff err contains an error whose concrete type matches that of referenceType.
func If ¶
If returns a predicate's return value the first time the predicate returns true.
Note: if any of the error types has been migrated from a previous package location or a different type, ensure that RegisterTypeMigration() was called prior to If().
func Is ¶
Is determines whether one of the causes of the given error or any of its causes is equivalent to some reference error.
Note: if any of the error types has been migrated from a previous package location or a different type, ensure that RegisterTypeMigration() was called prior to Is().
func IsAny ¶
IsAny is like Is except that multiple references are compared.
Note: if any of the error types has been migrated from a previous package location or a different type, ensure that RegisterTypeMigration() was called prior to IsAny().
func IsInterface ¶ added in v1.3.0
IsInterface returns true if err contains an error which implements the interface pointed to by referenceInterface. The type of referenceInterface must be a pointer to an interface type. If referenceInterface is not a pointer to an interface, this function will panic.
Example ¶
package main import ( "fmt" "net" "github.com/cockroachdb/errors/markers" "github.com/pkg/errors" ) func main() { base := &net.AddrError{ Addr: "ndn", Err: "ndn doesn't really exists :(", } err := errors.Wrap(base, "bummer") fmt.Println(markers.IsInterface(err, (*net.Error)(nil))) func() { defer func() { if r := recover(); r != nil { fmt.Println("*net.AddrError is not a pointer to an interface type so the call panics") } }() fmt.Println(markers.IsInterface(err, (*net.AddrError)(nil))) }() }
Output: true *net.AddrError is not a pointer to an interface type so the call panics
func IsType ¶ added in v1.3.0
IsType returns true if the outermost err object has a concrete type matching that of referenceType.
Example ¶
package main import ( "fmt" "net" "github.com/cockroachdb/errors/markers" "github.com/pkg/errors" ) type ExampleError struct{ msg string } func (e *ExampleError) Error() string { return e.msg } func main() { base := &ExampleError{"world"} err := errors.Wrap(base, "hello") fmt.Println(markers.HasType(err, (*ExampleError)(nil))) fmt.Println(markers.IsType(err, (*ExampleError)(nil))) fmt.Println(markers.HasType(err, nil)) fmt.Println(markers.IsType(err, nil)) fmt.Println(markers.HasType(err, (*net.AddrError)(nil))) fmt.Println(markers.IsType(err, (*net.AddrError)(nil))) }
Output: true false false false false false
Types ¶
This section is empty.