Open kubeplusplus opened 10 months ago
Can you please post what event
struct looks like and the validations on it. I can’t really help without it.
Is it possible the required tag contains an invisible char? I'd try deleting the tag and rewriting it just in case.
Ex.:
func TestNastyInvisibleChar(t *testing.T) {
v := validator.New(validator.WithRequiredStructEnabled())
type myTypeWithInvisibleChar struct {
// The "required" tag here contains an invisible char at the end
V string `validate:"required"`
}
type myType struct {
V string `validate:"required"`
}
// All good
if err := v.Struct(myType{"potato"}); err != nil {
t.Fatal(err)
}
// Panics with "Undefined validation function 'required' on field 'V'"
if err := v.Struct(myTypeWithInvisibleChar{"potato"}); err != nil {
t.Fatal(err)
}
}
@deankarn sorry about missing the event
, here it is
type Event struct {
Subject string `json:"subject" validate:"required"`
AppId string `json:"app_id" validate:"required"`
Type string `json:"type" validate:"required"`
Id string `json:"id" validate:"required"`
Data []byte `json:"data" validate:"required"`
Metadata map[string]string `json:"metadata"`
}
And an example of actual data that was dumped when the bug was happen
{
"subject": "kanthor.default.msg.app_2VXx8Qpkd9MAaKhYhEwnBLSliYJ.testing.traffic.stability",
"app_id": "app_2VXx8Qpkd9MAaKhYhEwnBLSliYJ",
"type": "testing.traffic.stability",
"id": "msg_2VXxhrM959iCT4pLFJI7TlOojZC",
"data": "eyJpZCI6Im1zZ18yVlh4aHJNOTU5aUNUNHBMRkpJN1RsT29qWkMiLCJ0aW1lc3RhbXAiOjE2OTQ5OTYzNDc4MjUsImJ1Y2tldCI6IjIwMjMwOTE4IiwiYXR0X2lkIjoiYXR0XzJWWHhocVROZzdaMEp1cmlpdnk3MFNya0xrSiIsInRpZXIiOiJkZWZhdWx0IiwiYXBwX2lkIjoiYXBwXzJWWHg4UXBrZDlNQWFLaFloRXduQkxTbGlZSiIsInR5cGUiOiJ0ZXN0aW5nLnRyYWZmaWMuc3RhYmlsaXR5IiwibWV0YWRhdGEiOnsia2FudGhvci5pZGVtcG90ZW5jeV9rZXkiOiI0MmY1NjUwNi1lN2ZmLTQ3MGYtODBhMS01Y2Q2M2Q4MTAyNjMifSwiaGVhZGVycyI6eyJIZWFkZXIiOnsiWC1DbGllbnQiOlsiazYuaW8iXX19LCJib2R5IjoiZXlKMWMyVnlibUZ0WlNJNkluVmZkbXhpWTNwNmEzRm5jVzF2Ym1weWIyZGhZMmRyZDNKdGFuTnNaRUJyWVc1MGFHOXliR0ZpY3k1amIyMGlmUT09In0=",
"metadata": {}
}
Some other information that may help
fatal error: gcmarknewobject called while doing checkmark
was raised instead of the bug I reportedv1.27.4+k3s1
, no limit resources (both cpu and ram)Is it possible the required tag contains an invisible char? I'd try deleting the tag and rewriting it just in case.
Ex.:
func TestNastyInvisibleChar(t *testing.T) { v := validator.New(validator.WithRequiredStructEnabled()) type myTypeWithInvisibleChar struct { // The "required" tag here contains an invisible char at the end V string `validate:"required"` } type myType struct { V string `validate:"required"` } // All good if err := v.Struct(myType{"potato"}); err != nil { t.Fatal(err) } // Panics with "Undefined validation function 'required' on field 'V'" if err := v.Struct(myTypeWithInvisibleChar{"potato"}); err != nil { t.Fatal(err) } }
I have test with this debug log
And it shows the normal
required
text
I also did a check with online tool
Your example shows this output
And this is the mine
Note: And the bug only happen during my stress test. In normal traffic, it's just fine
Package version eg. v9, v10: v10.15.4
Issue, Question or Enhancement:
I am developing a consumer that is using nats.io. In the consumer, I am using the validator to validate my message before process next step but got a weird bug
panic: Undefined validation function 'required' on field 'Subject'
. Definitely the validator must have the built-inrequired
function so something went wrongCode sample, to showcase or reproduce:
And the error I got
After take a look in the source code, I found where the panic was threw and put some test code by myself and test again
There is the error out I got after added my debug code. You can see the
has
variable isfalse
but in the mapv.validations
we haverequired
key