Skip to content

Commit

Permalink
Merge pull request #38456 from thaJeztah/make_errdefs_idempotent
Browse files Browse the repository at this point in the history
Make errdefs helpers idempotent
  • Loading branch information
thaJeztah committed Jan 9, 2019
2 parents 156b2ab + 264775b commit cb50188
Showing 1 changed file with 28 additions and 28 deletions.
56 changes: 28 additions & 28 deletions errdefs/helpers.go
Expand Up @@ -12,8 +12,8 @@ func (e errNotFound) Cause() error {

// NotFound is a helper to create an error of the class with the same name from any error type
func NotFound(err error) error {
if err == nil {
return nil
if err == nil || IsNotFound(err) {
return err
}
return errNotFound{err}
}
Expand All @@ -28,8 +28,8 @@ func (e errInvalidParameter) Cause() error {

// InvalidParameter is a helper to create an error of the class with the same name from any error type
func InvalidParameter(err error) error {
if err == nil {
return nil
if err == nil || IsInvalidParameter(err) {
return err
}
return errInvalidParameter{err}
}
Expand All @@ -44,8 +44,8 @@ func (e errConflict) Cause() error {

// Conflict is a helper to create an error of the class with the same name from any error type
func Conflict(err error) error {
if err == nil {
return nil
if err == nil || IsConflict(err) {
return err
}
return errConflict{err}
}
Expand All @@ -60,8 +60,8 @@ func (e errUnauthorized) Cause() error {

// Unauthorized is a helper to create an error of the class with the same name from any error type
func Unauthorized(err error) error {
if err == nil {
return nil
if err == nil || IsUnauthorized(err) {
return err
}
return errUnauthorized{err}
}
Expand All @@ -76,8 +76,8 @@ func (e errUnavailable) Cause() error {

// Unavailable is a helper to create an error of the class with the same name from any error type
func Unavailable(err error) error {
if err == nil {
return nil
if err == nil || IsUnavailable(err) {
return err
}
return errUnavailable{err}
}
Expand All @@ -92,8 +92,8 @@ func (e errForbidden) Cause() error {

// Forbidden is a helper to create an error of the class with the same name from any error type
func Forbidden(err error) error {
if err == nil {
return nil
if err == nil || IsForbidden(err) {
return err
}
return errForbidden{err}
}
Expand All @@ -108,8 +108,8 @@ func (e errSystem) Cause() error {

// System is a helper to create an error of the class with the same name from any error type
func System(err error) error {
if err == nil {
return nil
if err == nil || IsSystem(err) {
return err
}
return errSystem{err}
}
Expand All @@ -124,8 +124,8 @@ func (e errNotModified) Cause() error {

// NotModified is a helper to create an error of the class with the same name from any error type
func NotModified(err error) error {
if err == nil {
return nil
if err == nil || IsNotModified(err) {
return err
}
return errNotModified{err}
}
Expand All @@ -140,8 +140,8 @@ func (e errAlreadyExists) Cause() error {

// AlreadyExists is a helper to create an error of the class with the same name from any error type
func AlreadyExists(err error) error {
if err == nil {
return nil
if err == nil || IsAlreadyExists(err) {
return err
}
return errAlreadyExists{err}
}
Expand All @@ -156,8 +156,8 @@ func (e errNotImplemented) Cause() error {

// NotImplemented is a helper to create an error of the class with the same name from any error type
func NotImplemented(err error) error {
if err == nil {
return nil
if err == nil || IsNotImplemented(err) {
return err
}
return errNotImplemented{err}
}
Expand All @@ -172,8 +172,8 @@ func (e errUnknown) Cause() error {

// Unknown is a helper to create an error of the class with the same name from any error type
func Unknown(err error) error {
if err == nil {
return nil
if err == nil || IsUnknown(err) {
return err
}
return errUnknown{err}
}
Expand All @@ -188,8 +188,8 @@ func (e errCancelled) Cause() error {

// Cancelled is a helper to create an error of the class with the same name from any error type
func Cancelled(err error) error {
if err == nil {
return nil
if err == nil || IsCancelled(err) {
return err
}
return errCancelled{err}
}
Expand All @@ -204,8 +204,8 @@ func (e errDeadline) Cause() error {

// Deadline is a helper to create an error of the class with the same name from any error type
func Deadline(err error) error {
if err == nil {
return nil
if err == nil || IsDeadline(err) {
return err
}
return errDeadline{err}
}
Expand All @@ -220,8 +220,8 @@ func (e errDataLoss) Cause() error {

// DataLoss is a helper to create an error of the class with the same name from any error type
func DataLoss(err error) error {
if err == nil {
return nil
if err == nil || IsDataLoss(err) {
return err
}
return errDataLoss{err}
}
Expand Down

0 comments on commit cb50188

Please sign in to comment.