Skip to content

Add require.ErrorAsType for Go 1.26+ #1860

@mattjohnsonpint

Description

@mattjohnsonpint

Description

Go 1.26 introduced errors.AsType. It would be nice to have a Testify equivalent.

Use case

Previously, I might have:

var syntaxErr *json.SyntaxError
require.ErrorAs(t, err, &syntaxErr)

Now, with Go 1.26, I could write this:

_, ok := errors.AsType[*json.SyntaxError](err)
require.True(t, ok)

That removes the allocation, but loses details on failure.

Proposed solution

I'd like to be able to write:

require.ErrorAsType[*json.SyntaxError](t, err)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions