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

Function ErrorAs

assert/assertions.go:2138–2152  ·  view source on GitHub ↗

ErrorAs asserts that at least one of the errors in err's chain matches target, and if so, sets target to that error value. This is a wrapper for errors.As.

(t TestingT, err error, target interface{}, msgAndArgs ...interface{})

Source from the content-addressed store, hash-verified

2136// ErrorAs asserts that at least one of the errors in err's chain matches target, and if so, sets target to that error value.
2137// This is a wrapper for errors.As.
2138func ErrorAs(t TestingT, err error, target interface{}, msgAndArgs ...interface{}) bool {
2139 if h, ok := t.(tHelper); ok {
2140 h.Helper()
2141 }
2142 if errors.As(err, target) {
2143 return true
2144 }
2145
2146 chain := buildErrorChainString(err)
2147
2148 return Fail(t, fmt.Sprintf("Should be in error chain:\n"+
2149 "expected: %q\n"+
2150 "in chain: %s", target, chain,
2151 ), msgAndArgs...)
2152}
2153
2154// NotErrorAs asserts that none of the errors in err's chain matches target,
2155// but if so, sets target to that error value.

Callers 4

ErrorAsFunction · 0.92
ErrorAsfFunction · 0.70
TestErrorAsFunction · 0.70
ErrorAsMethod · 0.70

Calls 3

buildErrorChainStringFunction · 0.85
FailFunction · 0.70
HelperMethod · 0.65

Tested by 1

TestErrorAsFunction · 0.56