Skip to content

Commit 10e1d01

Browse files
committed
[patch] added a helper method to wrap with message, to wrap an error along with a message
1 parent f07a1f0 commit 10e1d01

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

helper.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,16 @@ func Wrap(err error) *Error {
2929
return newerr(err, "", file, line, e.eType)
3030
}
3131

32+
// WrapWithMsg wrap error with a message
33+
func WrapWithMsg(err error, msg string) *Error {
34+
_, file, line, _ := runtime.Caller(1)
35+
e, _ := err.(*Error)
36+
if e == nil {
37+
return newerr(err, msg, file, line, TypeInternal)
38+
}
39+
return newerr(err, msg, file, line, e.eType)
40+
}
41+
3242
// NewWithType returns an error instance with custom error type
3343
func NewWithType(msg string, etype errType) *Error {
3444
_, file, line, _ := runtime.Caller(1)

0 commit comments

Comments
 (0)