MCPcopy
hub / github.com/stretchr/testify / ErrorIs

Function ErrorIs

assert/assertions.go:2172–2194  ·  assert/assertions.go::ErrorIs

ErrorIs asserts that at least one of the errors in err's chain matches target. This is a wrapper for errors.Is.

(t TestingT, err, target error, msgAndArgs ...interface{})

Source from the content-addressed store, hash-verified

2170// ErrorIs asserts that at least one of the errors in err's chain matches target.
2171// This is a wrapper for errors.Is.
2172func ErrorIs(t TestingT, err, target error, msgAndArgs ...interface{}) bool {
2173 if h, ok := t.(tHelper); ok {
2174 h.Helper()
2175 }
2176 if errors.Is(err, target) {
2177 return true
2178 }
2179
2180 var expectedText string
2181 if target != nil {
2182 expectedText = target.Error()
2183 if err == nil {
2184 return Fail(t, fmt.Sprintf("Expected error with %q in chain but got nil.", expectedText), msgAndArgs...)
2185 }
2186 }
2187
2188 chain := buildErrorChainString(err, false)
2189
2190 return Fail(t, fmt.Sprintf("Target error should be in err chain:\n"+
2191 "expected: %q\n"+
2192 "in chain: %s", expectedText, chain,
2193 ), msgAndArgs...)
2194}
2195
2196// NotErrorIs asserts that none of the errors in err's chain matches target.
2197// This is a wrapper for errors.Is.

Callers 4

ErrorIsFunction · 0.92
ErrorIsfFunction · 0.70
TestErrorIsFunction · 0.70
ErrorIsMethod · 0.70

Calls 5

buildErrorChainStringFunction · 0.85
IsMethod · 0.80
FailFunction · 0.70
HelperMethod · 0.65
ErrorMethod · 0.45

Tested by 1

TestErrorIsFunction · 0.56