Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
fix: cause判断
Browse files Browse the repository at this point in the history
  • Loading branch information
白云辉 committed Jul 30, 2020
1 parent 170da52 commit 9ced77b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
6 changes: 2 additions & 4 deletions util.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func handleErr(err *error, _err interface{}) {
}
}

func handle(err error, msg string, args ...interface{}) error {
func handle(err error, msg string, args ...interface{}) *xerror {
if len(args) > 0 {
msg = fmt.Sprintf(msg, args...)
}
Expand Down Expand Up @@ -93,8 +93,6 @@ func trans(err error) *xerror {
case *xerror:
return err
default:
return &xerror{
Cause1: err,
}
return nil
}
}
8 changes: 4 additions & 4 deletions xerror.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func RespExit() {
return
}

fmt.Println(handle(err, "").(*xerror).p())
fmt.Println(handle(err, "").p())
debug.PrintStack()
os.Exit(1)
}
Expand Down Expand Up @@ -151,7 +151,7 @@ func ExitErr(_ interface{}, err error) {
return
}

fmt.Println(handle(err, "").(*xerror).p())
fmt.Println(handle(err, "").p())
debug.PrintStack()
os.Exit(1)
}
Expand All @@ -162,7 +162,7 @@ func ExitF(err error, msg string, args ...interface{}) {
return
}

fmt.Println(handle(err, msg, args...).(*xerror).p())
fmt.Println(handle(err, msg, args...).p())
debug.PrintStack()
os.Exit(1)
}
Expand All @@ -172,7 +172,7 @@ func Exit(err error) {
return
}

fmt.Println(handle(err, "").(*xerror).p())
fmt.Println(handle(err, "").p())
debug.PrintStack()
os.Exit(1)
}
Expand Down
5 changes: 5 additions & 0 deletions xerror_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package xerror_test

import (
"errors"
"fmt"
"github.com/pubgo/xerror"
"github.com/pubgo/xerror/errs"
Expand Down Expand Up @@ -28,6 +29,10 @@ func TestName(t *testing.T) {
xerror.Panic(a2(1, 2, 4, 5))
}

func TestExit(t *testing.T) {
xerror.Exit(errors.New("ss"))
}

func TestTry(t *testing.T) {
fmt.Println(xerror.Try(func() {
panic("hello")
Expand Down

0 comments on commit 9ced77b

Please sign in to comment.