MCPcopy Create free account
hub / github.com/stretchr/testify / NotErrorAs

Function NotErrorAs

assert/assertions.go:2156–2170  ·  view source on GitHub ↗

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{})

Source from the content-addressed store, hash-verified

2154// NotErrorAs asserts that none of the errors in err's chain matches target,
2155// but if so, sets target to that error value.
2156func 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
2172func buildErrorChainString(err error) string {
2173 if err == nil {

Callers 4

NotErrorAsFunction · 0.92
NotErrorAsfFunction · 0.70
TestNotErrorAsFunction · 0.70
NotErrorAsMethod · 0.70

Calls 3

buildErrorChainStringFunction · 0.85
FailFunction · 0.70
HelperMethod · 0.65

Tested by 1

TestNotErrorAsFunction · 0.56