Skip to content
Closed
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
7 changes: 5 additions & 2 deletions errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ func (ve ValidationErrors) Error() string {

buff := bytes.NewBufferString("")

var fe *fieldError
var fe FieldError

for i := 0; i < len(ve); i++ {

fe = ve[i].(*fieldError)
fe = ve[i].(FieldError)
buff.WriteString(fe.Error())
buff.WriteString("\n")
}
Expand Down Expand Up @@ -155,6 +155,9 @@ type FieldError interface {
// NOTE: is not registered translation can be found it returns the same
// as calling fe.Error()
Translate(ut ut.Translator) string

// Error returns the FieldError's error message
Error() string
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @joshhsoj1902 thanks for the PR

I think that only this addition is necessary

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @joeybloggs, I might be doing something wrong on my end, But for me, it only works when I also change the *fieldError references to the interface. When I just add Error() string to the interface I still get this error thrown

panic: interface conversion: validator.FieldError is *validator.fakeFieldError, not *validator.fieldError

(that panic happens on line 51, fakeFieldError is my implentation of FieldError)

My understanding is that since line 51 is trying to cast to the private struct, the only way the casting will pass is if the object being cast was also made from that private struct. and since it's private, I have no way of actually doing that.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll take a closer look, sorry for the delay I'm extremely busy

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No problem at all. If there is anything you would rather I do instead, let me know. I think there are a few ways to solve this.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@joshhsoj1902 would you be able to share your example, seems like the best place for me to start :)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey Joey, sorry for the slow reply. I do plan on circling back and creating a small sample program for you. Time is always the issue. Things should slow down a bit for me after next week.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no worries I only get a couple hours at most to take care of my open source stuff lately, tis the holiday season.

}

// compile time interface checks
Expand Down