]> 127.0.0.1 Git - part/.git/commitdiff
1
authorqydysky <qydysky@foxmail.com>
Mon, 25 Mar 2024 17:01:28 +0000 (01:01 +0800)
committerqydysky <qydysky@foxmail.com>
Mon, 25 Mar 2024 17:01:28 +0000 (01:01 +0800)
errors/errors.go
errors/errors_test.go

index 1d02ffce58ace60ee91a02fd9a0e504743c64a42..5e4330efd5360f8431876daaf94d667f2e0a4a9e 100644 (file)
@@ -14,6 +14,11 @@ func (t Error) Error() string {
        return t.Reason
 }
 
+func (t Error) WithReason(reason string) Error {
+       t.Reason = reason
+       return t
+}
+
 func Catch(e error, action string) bool {
        if v, ok := e.(Error); ok {
                if v.action == action {
index ec589cc50bddf2c58f83645fb6cc0a7b3b986a2a..83c7a47bea16631ff0485d8bf43bfd1c06ba7682 100644 (file)
@@ -55,3 +55,17 @@ func Test1(t *testing.T) {
                t.FailNow()
        }
 }
+
+func Test3(t *testing.T) {
+       e := New("1")
+       if e.Error() != "" {
+               t.FailNow()
+       }
+       e1 := e.WithReason("2")
+       if e.Error() != "" {
+               t.FailNow()
+       }
+       if e1.Error() != "2" {
+               t.FailNow()
+       }
+}