Skip to content
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
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,11 @@ func Cause(err error) error {
if !ok {
break
}
err = cause.Cause()
if cerr := cause.Cause(); cerr != nil {

Choose a reason for hiding this comment

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

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

err = cerr
} else {
break
}
}
return err
}