Skip to content

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

Merged
tlm merged 5 commits into
juju:masterfrom
barrettj12:const-error
Mar 24, 2022
Merged

[JUJU-759] Change error types to use new ConstError#54
tlm merged 5 commits into
juju:masterfrom
barrettj12:const-error

Conversation

@barrettj12

Copy link
Copy Markdown
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

jujubot commented Mar 22, 2022

Copy link
Copy Markdown
Contributor

Can one of the admins verify this patch?

1 similar comment
@jujubot

jujubot commented Mar 22, 2022

Copy link
Copy Markdown
Contributor

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
Copy Markdown
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

@tlm tlm left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

lgtm

Comment thread errortypes.go Outdated
Comment thread errortypes.go Outdated
Comment thread errortypes.go Outdated
Comment thread errortypes.go Outdated
Comment thread error.go

@hpidcock hpidcock left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Just one nagging question.

Comment thread errortypes.go
@barrettj12

Copy link
Copy Markdown
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