NotErrorAs asserts that none of the errors in err's chain matches target, but if so, sets target to that error value.
(t TestingT, err error, target interface{}, msgAndArgs ...interface{})
| 2154 | // NotErrorAs asserts that none of the errors in err's chain matches target, |
| 2155 | // but if so, sets target to that error value. |
| 2156 | func NotErrorAs(t TestingT, err error, target interface{}, msgAndArgs ...interface{}) bool { |
| 2157 | if h, ok := t.(tHelper); ok { |
| 2158 | h.Helper() |
| 2159 | } |
| 2160 | if !errors.As(err, target) { |
| 2161 | return true |
| 2162 | } |
| 2163 | |
| 2164 | chain := buildErrorChainString(err) |
| 2165 | |
| 2166 | return Fail(t, fmt.Sprintf("Target error should not be in err chain:\n"+ |
| 2167 | "found: %q\n"+ |
| 2168 | "in chain: %s", target, chain, |
| 2169 | ), msgAndArgs...) |
| 2170 | } |
| 2171 | |
| 2172 | func buildErrorChainString(err error) string { |
| 2173 | if err == nil { |