Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@titusjaka
Copy link

Summary

Add NotErrorAs methods to check that none of the errors in err's chain matches target.

Changes

  • add NotErrorAs and NotErrorAsf assertions to assert and require packages

Motivation

Sometimes, it's essential to check that error does not match an exact type.

func TestExample(t *testing.T) {
	err := errors.New("test error")

	var notFoundErr ErrNotFound
	assert.NotErrorAs(t, err, &notFoundErr)

	err = WrapNotFoundError(err)
	assert.ErrorAs(t, err, &notFoundErr)
}

Related issues

Closes #1066

@johanneswuerbach
Copy link

I was just searching for this function, to discover it is missing.

Maybe @boyan-soubachov could have a look? :-)

@Antonboom
Copy link

+1 for this PR.
and take a look to #1129

@dolmen dolmen added pkg-assert Change related to package testify/assert pkg-require Change related to package testify/require type-error Issue related to comparing values implementing the error interface labels Mar 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pkg-assert Change related to package testify/assert pkg-require Change related to package testify/require type-error Issue related to comparing values implementing the error interface

Projects

None yet

Development

Successfully merging this pull request may close these issues.

testify {assert|require} packages seem to be missing NotErrorAs methods.

4 participants