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{})
| 2170 | // ErrorIs asserts that at least one of the errors in err's chain matches target. |
| 2171 | // This is a wrapper for errors.Is. |
| 2172 | func 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. |