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{})
| 2090 | // ErrorIs asserts that at least one of the errors in err's chain matches target. |
| 2091 | // This is a wrapper for errors.Is. |
| 2092 | func ErrorIs(t TestingT, err, target error, msgAndArgs ...interface{}) bool { |
| 2093 | if h, ok := t.(tHelper); ok { |
| 2094 | h.Helper() |
| 2095 | } |
| 2096 | if errors.Is(err, target) { |
| 2097 | return true |
| 2098 | } |
| 2099 | |
| 2100 | var expectedText string |
| 2101 | if target != nil { |
| 2102 | expectedText = target.Error() |
| 2103 | } |
| 2104 | |
| 2105 | chain := buildErrorChainString(err) |
| 2106 | |
| 2107 | return Fail(t, fmt.Sprintf("Target error should be in err chain:\n"+ |
| 2108 | "expected: %q\n"+ |
| 2109 | "in chain: %s", expectedText, chain, |
| 2110 | ), msgAndArgs...) |
| 2111 | } |
| 2112 | |
| 2113 | // NotErrorIs asserts that none of the errors in err's chain matches target. |
| 2114 | // This is a wrapper for errors.Is. |