Skip to content

Question: how do you check error types with errors.As? #289

Description

@sevein

Hi @dnephin!

I've been doing something like the following to check error types with errors.As:

assert.Assert(t, errors.As(err, new(*osexec.ExitError)))

It works fine, but I keep wondering if it would make sense for gotest.tools to provide a built-in assert.ErrorAs helper - something along the lines of qt.ErrorAs.

Even if we want to keep the interface simple, handling wrapped errors in Go often needs a bit of extra complexity. A helper could make these checks easier to read and more consistent. I understand that adding more surface to the interface might not be ideal, so I totally get if this doesn't fit the goals of the project. Maybe it's just worth documenting the preferred pattern somewhere?

Thank you in advance.

Related discussion: #272.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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