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{})
| 2015 | // ErrorIs asserts that at least one of the errors in err's chain matches target. |
| 2016 | // This is a wrapper for errors.Is. |
| 2017 | func ErrorIs(t TestingT, err, target error, msgAndArgs ...interface{}) bool { |
| 2018 | if h, ok := t.(tHelper); ok { |
| 2019 | h.Helper() |
| 2020 | } |
| 2021 | if errors.Is(err, target) { |
| 2022 | return true |
| 2023 | } |
| 2024 | |
| 2025 | var expectedText string |
| 2026 | if target != nil { |
| 2027 | expectedText = target.Error() |
| 2028 | } |
| 2029 | |
| 2030 | chain := buildErrorChainString(err) |
| 2031 | |
| 2032 | return Fail(t, fmt.Sprintf("Target error should be in err chain:\n"+ |
| 2033 | "expected: %q\n"+ |
| 2034 | "in chain: %s", expectedText, chain, |
| 2035 | ), msgAndArgs...) |
| 2036 | } |
| 2037 | |
| 2038 | // NotErrorIs asserts that at none of the errors in err's chain matches target. |
| 2039 | // This is a wrapper for errors.Is. |
searching dependent graphs…