Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[JUJU-759] Change error types to use new ConstError #54

Merged
merged 5 commits into from
Mar 24, 2022

Conversation

barrettj12
Copy link
Contributor

Following #52, this library now supports errors.Is, errors.As, and errors.Unwrap from Go's standard errors library. This PR changes the IsX functions from errortypes.go to use errors.Is under the hood:

  • We've defined a new error type ConstError, whose values are "sentinel errors" representing a certain error type.
  • We've defined errWithType, which is an Err bundled with its error type errType ConstError. errWithType implements an Is method that compares its argument to errType. This ensures e.g. Is(e, NotFound) works as expected.
  • All the individual structs for different error types, e.g. timeout, notFound have been replaced with errWithType.
  • For X ConstError, Xf and NewX now return e errWithType where e.errType is X.
  • IsX functions are now implemented by comparison to X.

This is structurally quite a big change, but the errors should behave exactly as before (all the tests in errortypes_test.go pass).

@jujubot
Copy link
Contributor

jujubot commented Mar 22, 2022

Can one of the admins verify this patch?

1 similar comment
@jujubot
Copy link
Contributor

jujubot commented Mar 22, 2022

Can one of the admins verify this patch?

@barrettj12 barrettj12 changed the title Change error types to use new ConstError [JUJU-759] Change error types to use new ConstError Mar 22, 2022
@barrettj12
Copy link
Contributor Author

!!build!!

@barrettj12 barrettj12 marked this pull request as draft March 23, 2022 00:58
@barrettj12 barrettj12 marked this pull request as ready for review March 23, 2022 01:51
Copy link
Member

@tlm tlm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

errortypes.go Outdated Show resolved Hide resolved
errortypes.go Outdated Show resolved Hide resolved
errortypes.go Outdated Show resolved Hide resolved
errortypes.go Outdated Show resolved Hide resolved
error.go Show resolved Hide resolved
Copy link
Member

@hpidcock hpidcock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just one nagging question.

errortypes.go Show resolved Hide resolved
@barrettj12
Copy link
Contributor Author

$$merge$$

@tlm tlm merged commit d8c5072 into juju:master Mar 24, 2022
@barrettj12 barrettj12 deleted the const-error branch March 24, 2022 01:24
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.

5 participants