Documentation ¶
Overview ¶
Package testerror contains a `Error` type that implements the standard Error interface. Other packages in this repo use this type's methods to check the error of various operations.
Index ¶
- type Error
- func (e *Error) AsError() error
- func (e *Error) Error() string
- func (e *Error) ErrorContains(t *testing.T, substr string)
- func (e *Error) ErrorIsNil(t *testing.T)
- func (e *Error) ErrorIsNilFatal(t *testing.T)
- func (e *Error) ErrorNotContains(t *testing.T, substr string)
- func (e *Error) ErrorNotNil(t *testing.T)
- func (e *Error) ErrorNotNilFatal(t *testing.T)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Error ¶
type Error struct {
// contains filtered or unexported fields
}
Error is a simple error type that allows us to chain checks using methods. However due to Go's way of handling interface types, when a nil *Error value is used as an error type (e.g. when passed into a func accepting an error) the underlying concrete type is *Error and it will not pass the usual error != nil check. Instead use the AsError() method to get a regular error type. Or use the reflect package `val := reflect.ValueOf(myCheckError); val.IsNil()`.
func (*Error) AsError ¶
AsError returns a regular error type that can be used in the usual way. This fixes some issues when comparing nil types, which can fail as the underlying types are different. e.g. comparing the a nil error interface type to a nil *Error type from this package can fail.