gotestyourself / gotestyourself/gotest.tools

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

Open
#289 2 comments 0 reactions 0 assignees View on GitHub
documentation
Dominant language
Go
Stars
576
Forks
54
Avg merge
6d 3h
Merged PRs (30d)
2

Description

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](https://pkg.go.dev/github.com/go-quicktest/qt#example-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: https://github.com/gotestyourself/gotest.tools/issues/272.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.