feat: add detail type mismatch info in number fields check (#3386) (#3387)

This commit is contained in:
Xinyan Lu
2023-07-12 00:29:42 +08:00
committed by GitHub
parent 77da459165
commit b9c0c0f8b5
2 changed files with 32 additions and 1 deletions

View File

@@ -618,7 +618,7 @@ func (u *Unmarshaler) processFieldPrimitiveWithJSONNumber(fieldType reflect.Type
target.SetFloat(fValue)
default:
return newTypeMismatchError(fullName)
return newTypeMismatchErrorWithHint(fullName, value.Type().String(), typeKind.String())
}
SetValue(fieldType, value, target)
@@ -1054,6 +1054,10 @@ func newTypeMismatchError(name string) error {
return fmt.Errorf("type mismatch for field %q", name)
}
func newTypeMismatchErrorWithHint(name, errorType, rightType string) error {
return fmt.Errorf("type mismatch for field %q, expected %q, got %q", name, rightType, errorType)
}
func readKeys(key string) []string {
cacheKeysLock.Lock()
keys, ok := cacheKeys[key]