Skip to content
This repository has been archived by the owner on Dec 13, 2018. It is now read-only.

Commit

Permalink
genericError constructors can accept nil error
Browse files Browse the repository at this point in the history
if the error is nil, we do not populate generic error's message, but the
constructor will still return a valid error

Signed-off-by: Daniel, Dao Quang Minh <dqminh89@gmail.com>
  • Loading branch information
dqminh committed Mar 4, 2015
1 parent 4ce8d97 commit e22b589
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions generic_error.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,26 +25,32 @@ func newGenericError(err error, c ErrorCode) Error {
if le, ok := err.(Error); ok {
return le
}
return &genericError{
gerr := &genericError{
Timestamp: time.Now(),
Err: err,
Message: err.Error(),
ECode: c,
Stack: stacktrace.Capture(1),
}
if err != nil {
gerr.Message = err.Error()
}
return gerr
}

func newSystemError(err error) Error {
if le, ok := err.(Error); ok {
return le
}
return &genericError{
gerr := &genericError{
Timestamp: time.Now(),
Err: err,
ECode: SystemError,
Message: err.Error(),
Stack: stacktrace.Capture(1),
}
if err != nil {
gerr.Message = err.Error()
}
return gerr
}

type genericError struct {
Expand Down

0 comments on commit e22b589

Please sign in to comment.