Skip to content
This repository was archived by the owner on Dec 23, 2025. It is now read-only.

Commit 3c276ad

Browse files
committed
chore: improve error msg
Change-Id: I71ef652a8a81dc0874f56e6f64d8c1ecabeaf938
1 parent e1285dc commit 3c276ad

File tree

4 files changed

+10
-11
lines changed

4 files changed

+10
-11
lines changed

tagexpr.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ func (vm *VM) Run(structOrStructPtrOrReflectValue interface{}) (*TagExpr, error)
112112
u = tpack.Unpack(structOrStructPtrOrReflectValue)
113113
}
114114
if u.IsNil() {
115-
return nil, errors.New("unsupported nil")
115+
return nil, errors.New("unsupport data: nil")
116116
}
117117
u = u.UnderlyingElem()
118118
tid := u.RuntimeTypeID()
@@ -510,7 +510,7 @@ func (vm *VM) getStructType(t reflect.Type) (reflect.Type, error) {
510510
structType = structType.Elem()
511511
}
512512
if structType.Kind() != reflect.Struct {
513-
return nil, fmt.Errorf("unsupported %s", t.String())
513+
return nil, fmt.Errorf("unsupport type: %s", t.String())
514514
}
515515
return structType, nil
516516
}

validator/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,16 +98,16 @@ func Example() {
9898

9999
// Output:
100100
// true
101-
// validation failed: Email
101+
// invalid parameter: Email
102102
// true
103103
// C must be false when S.A>0
104104
// invalid d: [x y]
105-
// validation failed: e
105+
// invalid parameter: e
106106
// {"succ":false, "error":"validation failed: f.g"}
107107
// {"succ":false, "error":"validation failed: a/f.g"}
108108
// {"succ":false, "error":"validation failed: {k}/f.g"}
109109
// {"succ":false, "error":"validation failed: 0/0/f.g"}
110-
// validation failed: unsupported nil
110+
// unsupport data: nil
111111
// <nil>
112112
// <nil>
113113
}

validator/example_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,16 +79,16 @@ func Example() {
7979

8080
// Output:
8181
// true
82-
// validation failed: Email
82+
// invalid parameter: Email
8383
// true
8484
// C must be false when S.A>0
8585
// invalid d: [x y]
86-
// validation failed: e
86+
// invalid parameter: e
8787
// {"succ":false, "error":"validation failed: f.g"}
8888
// {"succ":false, "error":"validation failed: a/f.g"}
8989
// {"succ":false, "error":"validation failed: {k}/f.g"}
9090
// {"succ":false, "error":"validation failed: 0/0/f.g"}
91-
// validation failed: unsupported nil
91+
// unsupport data: nil
9292
// <nil>
9393
// <nil>
9494
}

validator/validator.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
package validator
1717

1818
import (
19-
"errors"
2019
"reflect"
2120
"strconv"
2221
"strings"
@@ -110,7 +109,7 @@ func (v *Validator) validate(selectorPrefix string, value reflect.Value) error {
110109

111110
expr, err := v.vm.Run(rv)
112111
if err != nil {
113-
return errors.New("validation failed: " + err.Error())
112+
return err
114113
}
115114
var errSelector string
116115
var valid bool
@@ -147,7 +146,7 @@ func (e *Error) Error() string {
147146
if e.Msg != "" {
148147
return e.Msg
149148
}
150-
return "validation failed: " + e.FailPath
149+
return "invalid parameter: " + e.FailPath
151150
}
152151

153152
func defaultErrorFactory(failPath, msg string) error {

0 commit comments

Comments
 (0)