This repository was archived by the owner on Dec 1, 2021. It is now read-only.
fix func Cause(error) error returning nil on the root cause error#221
Closed
win-t wants to merge 1 commit intopkg:masterfrom
Closed
fix func Cause(error) error returning nil on the root cause error#221win-t wants to merge 1 commit intopkg:masterfrom
func Cause(error) error returning nil on the root cause error#221win-t wants to merge 1 commit intopkg:masterfrom
Conversation
Some error struct have `Cause() error` method indicating the cause of
the error, but that method could return nil indicating that that itself
is the root cause in the error chain
look at this struct
```go
type myError struct {
message string
cause error
}
func (m *myError) Error() string { ... }
func (m *myError) Cause() error {
return m.cause
}
func New(message string) error {
return &myError{message: message}
}
```
Member
|
Can you please add a test so this change is not accidentally reverted in the future. Thank you.
… On 15 Jan 2020, at 19:16, Kurnia D Win ***@***.***> wrote:
Some error struct have Cause() error method indicating the cause of
the error, but that method could return nil indicating that that itself
is the root cause in the error chain
look at this struct
type myError struct {
message string
cause error
}
func (m *myError) Error() string { ... }
func (m *myError) Cause() error {
return m.cause
}
func New(message string) error {
return &myError{message: message}
}
You can view, comment on, or merge this pull request online at:
#221
Commit Summary
fix Cause
File Changes
M errors.go (6)
Patch Links:
https://github.com/pkg/errors/pull/221.patch
https://github.com/pkg/errors/pull/221.diff
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
puellanivis
reviewed
Jan 15, 2020
| break | ||
| } | ||
| err = cause.Cause() | ||
| if cerr := cause.Cause(); cerr != nil { |
There was a problem hiding this comment.
We can avoid the spurious break control flow by structuring this the other way around:
cerr := cause.Cause()
if cerr == nil {
return err
}
err = cerr
|
Also, this is a duplicate of #143 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Some error struct have
Cause() errormethod indicating the cause ofthe error, but that method could return nil indicating that that itself
is the root cause in the error chain
look at this struct