Skip to content
This repository has been archived by the owner on Dec 8, 2022. It is now read-only.

Extend Error Messages #80

Merged
merged 3 commits into from
Jan 9, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions faker.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ var (
ErrUnsupportedKindPtr = "Unsupported kind: %s Change Without using * (pointer) in Field of %s"
ErrUnsupportedKind = "Unsupported kind: %s"
ErrValueNotPtr = "Not a pointer value"
ErrTagNotSupported = "Tag unsupported"
ErrTagNotSupported = "Tag unsupported: %s"
ErrTagAlreadyExists = "Tag exists"
ErrMoreArguments = "Passed more arguments than is possible : (%d)"
ErrNotSupportedPointer = "Use sample:=new(%s)\n faker.FakeData(sample) instead"
Expand Down Expand Up @@ -563,7 +563,7 @@ func setDataWithTag(v reflect.Value, tag string) error {
switch v.Kind() {
case reflect.Ptr:
if _, exist := mapperTag[tag]; !exist {
return errors.New(ErrTagNotSupported)
return fmt.Errorf(ErrTagNotSupported,tag)
}
if _, def := defaultTag[tag]; !def {
res, err := mapperTag[tag](v)
Expand Down Expand Up @@ -595,7 +595,7 @@ func setDataWithTag(v reflect.Value, tag string) error {
return userDefinedMap(v, tag)
default:
if _, exist := mapperTag[tag]; !exist {
return errors.New(ErrTagNotSupported)
return fmt.Errorf(ErrTagNotSupported,tag)
}
res, err := mapperTag[tag](v)
if err != nil {
Expand Down Expand Up @@ -692,7 +692,7 @@ func userDefinedString(v reflect.Value, tag string) error {
}
}
if res == nil {
return errors.New(ErrTagNotSupported)
return fmt.Errorf(ErrTagNotSupported,tag)
}
val, _ := res.(string)
v.SetString(val)
Expand All @@ -715,7 +715,7 @@ func userDefinedNumber(v reflect.Value, tag string) error {
}
}
if res == nil {
return errors.New(ErrTagNotSupported)
return fmt.Errorf(ErrTagNotSupported,tag)
}

v.Set(reflect.ValueOf(res))
Expand All @@ -724,7 +724,7 @@ func userDefinedNumber(v reflect.Value, tag string) error {

func extractStringFromTag(tag string) (interface{}, error) {
if !strings.Contains(tag, Length) {
return nil, errors.New(ErrTagNotSupported)
return nil, fmt.Errorf(ErrTagNotSupported,tag)
}
len, err := extractNumberFromText(tag)
if err != nil {
Expand All @@ -736,7 +736,7 @@ func extractStringFromTag(tag string) (interface{}, error) {

func extractNumberFromTag(tag string, t reflect.Type) (interface{}, error) {
if !strings.Contains(tag, BoundaryStart) || !strings.Contains(tag, BoundaryEnd) {
return nil, errors.New(ErrTagNotSupported)
return nil,fmt.Errorf(ErrTagNotSupported,tag)
}
valuesStr := strings.SplitN(tag, comma, -1)
if len(valuesStr) != 2 {
Expand Down