Skip to content

Commit

Permalink
if wrapping nil return nil
Browse files Browse the repository at this point in the history
  • Loading branch information
Greg Weber committed Jun 18, 2024
1 parent 3b9a882 commit 6bdf1ea
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions error_code.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,23 +185,35 @@ func (wrapped wrappedErrorCode) Unwrap() error {
}

// Wrap is a convenience that calls errors.Wrap but still returns the ErrorCode interface
// If a nil ErrorCode is given it will be returned as nil
func Wrap(errCode ErrorCode, msg string) ErrorCode {
if errCode == nil {
return nil
}
return wrappedErrorCode{
Err: errors.Wrap(errCode, msg),
ErrorCode: errCode,
}
}

// Wrapf is a convenience that calls errors.Wrapf but still returns the ErrorCode interface
// If a nil ErrorCode is given it will be returned as nil
func Wrapf(errCode ErrorCode, msg string, args ...interface{}) ErrorCode {
if errCode == nil {
return nil
}
return wrappedErrorCode{
Err: errors.Wrapf(errCode, msg, args...),
ErrorCode: errCode,
}
}

// Wraps is a convenience that calls errors.Wraps but still returns the ErrorCode interface
// If a nil ErrorCode is given it will be returned as nil
func Wraps(errCode ErrorCode, msg string, args ...interface{}) ErrorCode {
if errCode == nil {
return nil
}
return wrappedErrorCode{
Err: errors.Wraps(errCode, msg, args...),
ErrorCode: errCode,
Expand Down

0 comments on commit 6bdf1ea

Please sign in to comment.