Error
Asserting Errors
Assertions
All links point to https://pkg.go.dev/github.com/go-openapi/testify/v2
This domain exposes 10 functionalities. Generic assertions are marked with a . Assertions requiring a newer Go toolchain are marked with a version badge, e.g. go1.26 (the assertion is unavailable on older toolchains).
EqualError
EqualError asserts that a function returned a non-nil error (i.e. an error) and that it is equal to the provided error.
| Signature | Usage |
|---|---|
assert.EqualError(t T, err error, errString string, msgAndArgs ...any) bool | package-level function |
assert.EqualErrorf(t T, err error, errString string, msg string, args ...any) bool | formatted variant |
assert.(*Assertions).EqualError(err error, errString string) bool | method variant |
assert.(*Assertions).EqualErrorf(err error, errString string, msg string, args ..any) | method formatted variant |
| Signature | Usage |
|---|---|
require.EqualError(t T, err error, errString string, msgAndArgs ...any) bool | package-level function |
require.EqualErrorf(t T, err error, errString string, msg string, args ...any) bool | formatted variant |
require.(*Assertions).EqualError(err error, errString string) bool | method variant |
require.(*Assertions).EqualErrorf(err error, errString string, msg string, args ..any) | method formatted variant |
| Signature | Usage |
|---|---|
assertions.EqualError(t T, err error, errString string, msgAndArgs ...any) bool | internal implementation |
Source: github.com/go-openapi/testify/v2/internal/assertions#EqualError
Error
Error asserts that a function returned a non-nil error (i.e. an error).
| Signature | Usage |
|---|---|
assert.Error(t T, err error, msgAndArgs ...any) bool | package-level function |
assert.Errorf(t T, err error, msg string, args ...any) bool | formatted variant |
assert.(*Assertions).Error(err error) bool | method variant |
assert.(*Assertions).Errorf(err error, msg string, args ..any) | method formatted variant |
| Signature | Usage |
|---|---|
require.Error(t T, err error, msgAndArgs ...any) bool | package-level function |
require.Errorf(t T, err error, msg string, args ...any) bool | formatted variant |
require.(*Assertions).Error(err error) bool | method variant |
require.(*Assertions).Errorf(err error, msg string, args ..any) | method formatted variant |
| Signature | Usage |
|---|---|
assertions.Error(t T, err error, msgAndArgs ...any) bool | internal implementation |
Source: github.com/go-openapi/testify/v2/internal/assertions#Error
ErrorAs
ErrorAs asserts that at least one of the errors in err’s chain matches target, and if so, sets target to that error value.
This is a wrapper for errors.As.
| Signature | Usage |
|---|---|
assert.ErrorAs(t T, err error, target any, msgAndArgs ...any) bool | package-level function |
assert.ErrorAsf(t T, err error, target any, msg string, args ...any) bool | formatted variant |
assert.(*Assertions).ErrorAs(err error, target any) bool | method variant |
assert.(*Assertions).ErrorAsf(err error, target any, msg string, args ..any) | method formatted variant |
| Signature | Usage |
|---|---|
require.ErrorAs(t T, err error, target any, msgAndArgs ...any) bool | package-level function |
require.ErrorAsf(t T, err error, target any, msg string, args ...any) bool | formatted variant |
require.(*Assertions).ErrorAs(err error, target any) bool | method variant |
require.(*Assertions).ErrorAsf(err error, target any, msg string, args ..any) | method formatted variant |
| Signature | Usage |
|---|---|
assertions.ErrorAs(t T, err error, target any, msgAndArgs ...any) bool | internal implementation |
Source: github.com/go-openapi/testify/v2/internal/assertions#ErrorAs
ErrorAsType[E error] go1.26
ErrorAsType asserts that at least one of the errors in err’s chain is of type E.
It is the type-safe counterpart of ErrorAs, built on the go1.26 errors.AsType: the expected type is the type parameter E (checked at compile time, no reflection), rather than the untyped any target used by ErrorAs.
target receives the matched error when the assertion succeeds. It may be nil, for callers that only want to know whether the chain holds an error of type E: in that case E cannot be inferred and must be supplied explicitly.
This assertion requires go1.26 or newer; it is unavailable on older toolchains.
| Signature | Usage |
|---|---|
assert.ErrorAsType[E error](t T, err error, target *E, msgAndArgs ...any) bool | package-level function |
assert.ErrorAsTypef[E error](t T, err error, target *E, msg string, args ...any) bool | formatted variant |
| Signature | Usage |
|---|---|
require.ErrorAsType[E error](t T, err error, target *E, msgAndArgs ...any) bool | package-level function |
require.ErrorAsTypef[E error](t T, err error, target *E, msg string, args ...any) bool | formatted variant |
| Signature | Usage |
|---|---|
assertions.ErrorAsType[E error](t T, err error, target *E, msgAndArgs ...any) bool | internal implementation |
Source: github.com/go-openapi/testify/v2/internal/assertions#ErrorAsType
ErrorContains
ErrorContains asserts that a function returned a non-nil error (i.e. an error) and that the error contains the specified substring.
| Signature | Usage |
|---|---|
assert.ErrorContains(t T, err error, contains string, msgAndArgs ...any) bool | package-level function |
assert.ErrorContainsf(t T, err error, contains string, msg string, args ...any) bool | formatted variant |
assert.(*Assertions).ErrorContains(err error, contains string) bool | method variant |
assert.(*Assertions).ErrorContainsf(err error, contains string, msg string, args ..any) | method formatted variant |
| Signature | Usage |
|---|---|
require.ErrorContains(t T, err error, contains string, msgAndArgs ...any) bool | package-level function |
require.ErrorContainsf(t T, err error, contains string, msg string, args ...any) bool | formatted variant |
require.(*Assertions).ErrorContains(err error, contains string) bool | method variant |
require.(*Assertions).ErrorContainsf(err error, contains string, msg string, args ..any) | method formatted variant |
| Signature | Usage |
|---|---|
assertions.ErrorContains(t T, err error, contains string, msgAndArgs ...any) bool | internal implementation |
Source: github.com/go-openapi/testify/v2/internal/assertions#ErrorContains
ErrorIs
ErrorIs asserts that at least one of the errors in err’s chain matches target.
This is a wrapper for errors.Is.
| Signature | Usage |
|---|---|
assert.ErrorIs(t T, err error, target error, msgAndArgs ...any) bool | package-level function |
assert.ErrorIsf(t T, err error, target error, msg string, args ...any) bool | formatted variant |
assert.(*Assertions).ErrorIs(err error, target error) bool | method variant |
assert.(*Assertions).ErrorIsf(err error, target error, msg string, args ..any) | method formatted variant |
| Signature | Usage |
|---|---|
require.ErrorIs(t T, err error, target error, msgAndArgs ...any) bool | package-level function |
require.ErrorIsf(t T, err error, target error, msg string, args ...any) bool | formatted variant |
require.(*Assertions).ErrorIs(err error, target error) bool | method variant |
require.(*Assertions).ErrorIsf(err error, target error, msg string, args ..any) | method formatted variant |
| Signature | Usage |
|---|---|
assertions.ErrorIs(t T, err error, target error, msgAndArgs ...any) bool | internal implementation |
Source: github.com/go-openapi/testify/v2/internal/assertions#ErrorIs
NoError
NoError asserts that a function returned a nil error (i.e. no error).
| Signature | Usage |
|---|---|
assert.NoError(t T, err error, msgAndArgs ...any) bool | package-level function |
assert.NoErrorf(t T, err error, msg string, args ...any) bool | formatted variant |
assert.(*Assertions).NoError(err error) bool | method variant |
assert.(*Assertions).NoErrorf(err error, msg string, args ..any) | method formatted variant |
| Signature | Usage |
|---|---|
require.NoError(t T, err error, msgAndArgs ...any) bool | package-level function |
require.NoErrorf(t T, err error, msg string, args ...any) bool | formatted variant |
require.(*Assertions).NoError(err error) bool | method variant |
require.(*Assertions).NoErrorf(err error, msg string, args ..any) | method formatted variant |
| Signature | Usage |
|---|---|
assertions.NoError(t T, err error, msgAndArgs ...any) bool | internal implementation |
Source: github.com/go-openapi/testify/v2/internal/assertions#NoError
NotErrorAs
NotErrorAs asserts that none of the errors in err’s chain matches target, but if so, sets target to that error value.
| Signature | Usage |
|---|---|
assert.NotErrorAs(t T, err error, target any, msgAndArgs ...any) bool | package-level function |
assert.NotErrorAsf(t T, err error, target any, msg string, args ...any) bool | formatted variant |
assert.(*Assertions).NotErrorAs(err error, target any) bool | method variant |
assert.(*Assertions).NotErrorAsf(err error, target any, msg string, args ..any) | method formatted variant |
| Signature | Usage |
|---|---|
require.NotErrorAs(t T, err error, target any, msgAndArgs ...any) bool | package-level function |
require.NotErrorAsf(t T, err error, target any, msg string, args ...any) bool | formatted variant |
require.(*Assertions).NotErrorAs(err error, target any) bool | method variant |
require.(*Assertions).NotErrorAsf(err error, target any, msg string, args ..any) | method formatted variant |
| Signature | Usage |
|---|---|
assertions.NotErrorAs(t T, err error, target any, msgAndArgs ...any) bool | internal implementation |
Source: github.com/go-openapi/testify/v2/internal/assertions#NotErrorAs
NotErrorAsType[E error] go1.26
NotErrorAsType asserts that none of the errors in err’s chain is of type E.
It is the type-safe counterpart of NotErrorAs, built on the go1.26 errors.AsType.
target is only used to infer the type parameter E and is never assigned; it may be nil, in which case E must be supplied explicitly.
This assertion requires go1.26 or newer; it is unavailable on older toolchains.
| Signature | Usage |
|---|---|
assert.NotErrorAsType[E error](t T, err error, target *E, msgAndArgs ...any) bool | package-level function |
assert.NotErrorAsTypef[E error](t T, err error, target *E, msg string, args ...any) bool | formatted variant |
| Signature | Usage |
|---|---|
require.NotErrorAsType[E error](t T, err error, target *E, msgAndArgs ...any) bool | package-level function |
require.NotErrorAsTypef[E error](t T, err error, target *E, msg string, args ...any) bool | formatted variant |
| Signature | Usage |
|---|---|
assertions.NotErrorAsType[E error](t T, err error, target *E, msgAndArgs ...any) bool | internal implementation |
Source: github.com/go-openapi/testify/v2/internal/assertions#NotErrorAsType
NotErrorIs
NotErrorIs asserts that none of the errors in err’s chain matches target.
This is a wrapper for errors.Is.
| Signature | Usage |
|---|---|
assert.NotErrorIs(t T, err error, target error, msgAndArgs ...any) bool | package-level function |
assert.NotErrorIsf(t T, err error, target error, msg string, args ...any) bool | formatted variant |
assert.(*Assertions).NotErrorIs(err error, target error) bool | method variant |
assert.(*Assertions).NotErrorIsf(err error, target error, msg string, args ..any) | method formatted variant |
| Signature | Usage |
|---|---|
require.NotErrorIs(t T, err error, target error, msgAndArgs ...any) bool | package-level function |
require.NotErrorIsf(t T, err error, target error, msg string, args ...any) bool | formatted variant |
require.(*Assertions).NotErrorIs(err error, target error) bool | method variant |
require.(*Assertions).NotErrorIsf(err error, target error, msg string, args ..any) | method formatted variant |
| Signature | Usage |
|---|---|
assertions.NotErrorIs(t T, err error, target error, msgAndArgs ...any) bool | internal implementation |
Source: github.com/go-openapi/testify/v2/internal/assertions#NotErrorIs
Generated with github.com/go-openapi/testify/codegen/v2