-
Notifications
You must be signed in to change notification settings - Fork 700
Conversation
add function `Is`, `As` and `Unwrap`, like std errors, so that we can continue to use pkg/errors with go1.13 compatibility Signed-off-by: Sherlock Holo <sherlockya@gmail.com>
Signed-off-by: Sherlock Holo <sherlockya@gmail.com>
update makefile to download dependencies before test anything Signed-off-by: Sherlock Holo <sherlockya@gmail.com>
Signed-off-by: Sherlock Holo <sherlockya@gmail.com>
Signed-off-by: Sherlock Holo <sherlockya@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you’re building tests upon pure wrappers of external packages, which should not be our responsibility.
Signed-off-by: Sherlock Holo <sherlockya@gmail.com>
Signed-off-by: Sherlock Holo <sherlockya@gmail.com>
If this package is going into maintenance mode (according to the README), why add new API surface area? "Maintenance mode" and "drop-in replacement" seem like competing motivations, especially as the standard library beefs up its package. |
The change is small, it improves the user experience, and probably improves interoperability of tooling as well (less imports, don't have to alias the import). I think it would be silly not to include it personally. |
@aperezg please see are there anything need to improve, if has, let me know to optimize codes :-) |
`Unwrap` just use type assert, it doesn't need go1.13 actually Signed-off-by: Sherlock Holo <sherlockya@gmail.com>
Signed-off-by: Sherlock Holo <sherlockya@gmail.com>
errors.go
Outdated
@@ -286,3 +286,13 @@ func Cause(err error) error { | |||
} | |||
return err | |||
} | |||
|
|||
func Unwrap(err error) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why reimplement this function rather than wrapping it? Someone using Go 1.12 or older will not be using the new style of errors. This creates a risk of incompatibility if Go 1.14 subtly changes its Unwrap
implementation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@aperezg emm.... this is a problem if go1.14 changes Unwrap
implment, so... we should keep Unwrap
>= go1.13?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But why is the problem to maintain the Unwrap function like today? I understand that the Unwrap is an interface on a std library right? Sorry, I try to understand what is the point to change the implementation a wrapped with the standard library. I doubt that they implement a breaking change on that, no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
go1.14 cannot break the semantics of Unwrap
without violating the go1 compat guarantee.
These same considerations apply to successive point releases. For instance, code that runs under Go 1.2 should be compatible with Go 1.2.1, Go 1.3, Go 1.4, etc., although not necessarily with Go 1.1 since it may use features added only in Go 1.2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This functionality should likely be folded into Cause()
and Unwrap()
here just calls Cause()
.
c.f. #215
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That Unwrap
only works for specific permutations of wrapping with the standard library and causer
s.
In the wild, we should expect any possible permutation of wrapping, including multiple times being wrapped in an alternating manner.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unwrap
should only unwrap error one times, no matter the inner error implement unwrap interface or not, like std Unwrap
do.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But this code would fail to fully unwrap: Unwrap(fmt.Errorf("wrap1: %w", myPrivateCauserOnlyError(fmt.Errorf("wrap 3: %w", err), "wrap2:")))
where I would get the fmt.Errorf("wrap3: %w", err)
error not the original err
, which would not be the expected behavior.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤦♀ the standard library Unwrap
does not continuously unwrap a function, until it reaches the end result, unlike how Cause
in this package works.
If we implement Unwrap ourselves, may create a risk of incompatibility if Go 1.14 subtly changes its `Unwrap` implementation. <go1.13 users doesn't have `Is` or `As`, if they want, they will use xerrors and it also provides `Unwrap` Signed-off-by: Sherlock Holo <sherlockya@gmail.com>
@jayschwa why return I.e., |
Because we want to match the behavior of the standard library's
|
What's the status on this PR, it's been almost a month since the initiative to update this package started. I'd be happy to help out any way I can. |
you can tell us if you want these functions only support 113 or all version
Johan Lejdung <notifications@github.com> 于 2019年11月24日周日 20:46写道:
… What's the status on this PR, it's been almost a month since the
initiative to update this package started. I'd be happy to help out any way
I can.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#213?email_source=notifications&email_token=ACNA6KLNDDD27ZBXC5HOZS3QVJZTBA5CNFSM4JIMD2U2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEFAKNTQ#issuecomment-557885134>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ACNA6KJ3S7DYMDY2VEO5RN3QVJZTBANCNFSM4JIMD2UQ>
.
|
Sorry I was very busy this month, I'll try to catch up with all comments ASAP |
@aperezg I think this PR should focus on add this functions for 1.13, and if many<1.13 users want them, we cloud create another PR to help them |
I agree with that @Sherlock-Holo The pr should focus on adding support for the new |
How soon could this get merged? I would really love to see this PR merged in master and tagged so we can use Go 1.13 functions. |
these days I am a little busy too…maybe this weekend I can update this pr
for just support these functions >=1.13
Artūrs Jānis Pētersons <notifications@github.com> 于 2019年12月6日周五 21:24写道:
… How soon could this get merged? I would really love to see this PR merged
in master and tagged so we can use Go 1.13 functions.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#213?email_source=notifications&email_token=ACNA6KLGVZRYDBMULWRDMV3QXJHAPA5CNFSM4JIMD2U2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEGECFXA#issuecomment-562569948>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ACNA6KJCDXV33TCZNHPEPBLQXJHAPANCNFSM4JIMD2UQ>
.
|
For me, I think that this PR would be only for add support to the new features on Go 1.13, so I think that as is now seems good.
@Sherlock-Holo What do yo need to update on this PR to be merged? Furthermore I see that @puellanivis and @jayschwa I see that you also reviewed this PR, is good for you now? |
@aperezg Nothing need to do before merge, now this PR only add new feature for >= 1.13 |
add function
Is
,As
andUnwrap
, like std errors, so that we cancontinue to use pkg/errors with go1.13 compatibility