]> 127.0.0.1 Git - part/.git/commitdiff
1 (#12) v0.28.20250120153835
authorqydysky <qydysky@foxmail.com>
Mon, 20 Jan 2025 15:32:38 +0000 (23:32 +0800)
committerGitHub <noreply@github.com>
Mon, 20 Jan 2025 15:32:38 +0000 (23:32 +0800)
errors/errors.go
errors/errors_test.go

index 3e8bad03d2f3599adc37fa5567fb48b29d81282a..63554c336ff9bad255258bf6025162c80d8789e4 100644 (file)
@@ -6,6 +6,10 @@ import (
 
 type Action string
 
+func (t Action) Append(child string) Action {
+       return Action(string(t) + child)
+}
+
 type Error struct {
        son    error
        Reason string
@@ -33,7 +37,7 @@ func Catch(e error, action Action) bool {
 }
 
 // Grow will append e to fe
-func Grow(fe Error, e error) Error {
+func Append(fe Error, e error) Error {
        if v, ok := e.(Error); ok {
                fe.son = v
        } else {
index da0d1c6f88da29021c616e1711d0e444e5e0908c..9836814bda87566e42f4544faf7a9c2509c1e9c1 100644 (file)
@@ -8,6 +8,7 @@ import (
 
 var a0 = Action("a0")
 var a1 = Action("a1")
+var a11 = a1.Append("1")
 
 func TestXxx(t *testing.T) {
        var err error
@@ -22,9 +23,9 @@ func TestXxx(t *testing.T) {
                t.Fail()
        }
 
-       err = Grow(New("r1", a1), err)
+       err = Append(New("r1", a11), err)
 
-       if !Catch(err, a1) {
+       if !Catch(err, a11) {
                t.Fail()
        }
 
@@ -34,7 +35,7 @@ func TestXxx(t *testing.T) {
 }
 
 func TestXxx2(t *testing.T) {
-       err := Grow(New("r1", a1), io.EOF)
+       err := Append(New("r1", a1), io.EOF)
        if !Catch(err, a1) {
                t.Fatal()
        }