Skip to content

Use errors.As() and errors.Is() to unwrap errors#2291

Merged
crosbymichael merged 2 commits intoopencontainers:masterfrom
kolyshkin:errors-unwrap-v2
Apr 3, 2020
Merged

Use errors.As() and errors.Is() to unwrap errors#2291
crosbymichael merged 2 commits intoopencontainers:masterfrom
kolyshkin:errors-unwrap-v2

Conversation

@kolyshkin
Copy link
Copy Markdown
Contributor

My previous attempt (#2280) was a bit immature (though it worked).

Using errors.Unwrap() is not the best thing to do, since it returns
nil in case of an error which was not wrapped. More to say,
errors package provides more elegant ways to check for underlying
errors, such as errors.As() and errors.Is().

Revert #2280, and use errors.Is() and errors.As()

Make use of errors.Is() and errors.As() where appropriate to check
the underlying error. The biggest motivation is to simplify the code.

The feature requires go 1.13 but since merging #2256 we are already
not supporting go 1.12 (which is an unsupported release anyway).

…unwrap"

Using errors.Unwrap() is not the best thing to do, since it returns
nil in case of an error which was not wrapped. More to say,
errors package provides more elegant ways to check for underlying
errors, such as errors.As() and errors.Is().

This reverts commit f8e1388, reversing
changes made to 6ca9d8e.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
Make use of errors.Is() and errors.As() where appropriate to check
the underlying error. The biggest motivation is to simplify the code.

The feature requires go 1.13 but since merging opencontainers#2256 we are already
not supporting go 1.12 (which is an unsupported release anyway).

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
@kolyshkin
Copy link
Copy Markdown
Contributor Author

@AkihiroSuda @crosbymichael @mrunalp PTAL

@AkihiroSuda
Copy link
Copy Markdown
Member

AkihiroSuda commented Apr 3, 2020

LGTM

Approved with PullApprove

@mrunalp
Copy link
Copy Markdown
Contributor

mrunalp commented Apr 3, 2020

LGTM

Approved with PullApprove

@kolyshkin kolyshkin changed the title Revert "Merge pull request #2280 from kolyshkin/errors-unwrap" Use errors.As() and errors.Is() to unwrap errors Apr 3, 2020
@crosbymichael
Copy link
Copy Markdown
Member

crosbymichael commented Apr 3, 2020

LGTM

Approved with PullApprove

@crosbymichael crosbymichael merged commit e4363b0 into opencontainers:master Apr 3, 2020
kolyshkin added a commit to kolyshkin/runc that referenced this pull request Apr 18, 2020
This is a forgotten hunk from PR opencontainers#2291.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
@kolyshkin kolyshkin mentioned this pull request Apr 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants