Skip to content

Commit 159e489

Browse files
committed
Add E.Cause1
1 parent d39c2c2 commit 159e489

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

common/exceptions/cause.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,16 @@ func (e *causeError) Error() string {
1212
func (e *causeError) Unwrap() error {
1313
return e.cause
1414
}
15+
16+
type causeError1 struct {
17+
error
18+
cause error
19+
}
20+
21+
func (e *causeError1) Error() string {
22+
return e.error.Error() + ": " + e.cause.Error()
23+
}
24+
25+
func (e *causeError1) Unwrap() []error {
26+
return []error{e.error, e.cause}
27+
}

common/exceptions/error.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,13 @@ func Cause(cause error, message ...any) error {
3232
return &causeError{F.ToString(message...), cause}
3333
}
3434

35+
func Cause1(err error, cause error) error {
36+
if cause == nil {
37+
panic("cause on an nil error")
38+
}
39+
return &causeError1{err, cause}
40+
}
41+
3542
func Extend(cause error, message ...any) error {
3643
if cause == nil {
3744
panic("extend on an nil error")

0 commit comments

Comments
 (0)