{"record":{"id":"f3e40bf5a2e90606","repo":"go-playground/validator","slug":"invalid-validation-tag-on-field-s","errorCode":null,"errorMessage":"Invalid validation tag on field '%s'","messagePattern":"Invalid validation tag on field '(.+?)'","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"cache.go","lineNumber":286,"sourceCode":"\n\t\t\tfor j := 0; j < len(orVals); j++ {\n\t\t\t\tvals := strings.SplitN(orVals[j], tagKeySeparator, 2)\n\t\t\t\tif noAlias {\n\t\t\t\t\talias = vals[0]\n\t\t\t\t\tcurrent.aliasTag = alias\n\t\t\t\t} else {\n\t\t\t\t\tcurrent.actualAliasTag = t\n\t\t\t\t}\n\n\t\t\t\tif j > 0 {\n\t\t\t\t\tcurrent.next = &cTag{aliasTag: alias, actualAliasTag: current.actualAliasTag, hasAlias: hasAlias, hasTag: true}\n\t\t\t\t\tcurrent = current.next\n\t\t\t\t}\n\t\t\t\tcurrent.hasParam = len(vals) > 1\n\n\t\t\t\tcurrent.tag = vals[0]\n\t\t\t\tif len(current.tag) == 0 {\n\t\t\t\t\tpanic(strings.TrimSpace(fmt.Sprintf(invalidValidation, fieldName)))\n\t\t\t\t}\n\n\t\t\t\tif wrapper, ok := v.validations[current.tag]; ok {\n\t\t\t\t\tcurrent.fn = wrapper.fn\n\t\t\t\t\tcurrent.runValidationWhenNil = wrapper.runValidationOnNil\n\t\t\t\t} else if aliasTag, isAlias := v.aliases[current.tag]; isAlias {\n\t\t\t\t\taliasFirst, aliasLast := v.parseFieldTagsRecursive(aliasTag, fieldName, current.tag, true)\n\n\t\t\t\t\tcurrent.tag = aliasFirst.tag\n\t\t\t\t\tcurrent.fn = aliasFirst.fn\n\t\t\t\t\tcurrent.runValidationWhenNil = aliasFirst.runValidationWhenNil\n\t\t\t\t\tcurrent.hasParam = aliasFirst.hasParam\n\t\t\t\t\tcurrent.param = aliasFirst.param\n\t\t\t\t\tcurrent.typeof = aliasFirst.typeof\n\t\t\t\t\tcurrent.hasAlias = true\n\n\t\t\t\t\tif aliasFirst.next != nil {\n\t\t\t\t\t\tnextInChain := current.next","sourceCodeStart":268,"sourceCodeEnd":304,"githubUrl":"https://github.com/go-playground/validator/blob/facf128d2eecf42bd4ff447adc961aa21bb64aed/cache.go#L268-L304","documentation":"A tag segment parsed to an empty validator name (e.g. a leading/trailing comma or `,|,` leaving an empty tag before params). cache.go panics with \"Invalid validation tag on field '<FieldName>'\" when building the tag cache for the struct.","triggerScenarios":"Struct tag containing empty tag entries such as `validate:\",required\"`, `validate:\"required,,min=1\"`, or an alias expanding to an empty tag; malformed tags from code-generated structs.","commonSituations":"String-built tags where variables are empty (fmt.Sprintf(\"validate:%s,%s\", emptyVar, \"required\")); trailing commas after refactors; ORM/struct generators emitting extra commas.","solutions":["Remove empty tag entries / duplicate commas from the struct tag","Fix the code that generates the tag string so it never emits an empty segment","Check aliases: an alias expanding to an empty string produces this panic","Add a startup test validating a representative struct instance to fail fast"],"exampleFix":"// before\nName string `validate:\",required\"`\n// after\nName string `validate:\"required\"`","handlingStrategy":"validation","validationCode":"func checkEmptyTags(t reflect.StructTag) error {\n    for i, tg := range strings.Split(t.Get(\"validate\"), \",\") {\n        if strings.TrimSpace(tg) == \"\" {\n            return fmt.Errorf(\"empty tag segment at index %d\", i)\n        }\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":"func validateStrict(s any) (err error) {\n    defer func() {\n        if r := recover(); r != nil {\n            if strings.Contains(fmt.Sprint(r), \"Invalid validation tag\") {\n                err = fmt.Errorf(\"malformed struct tag: %v\", r)\n            } else { panic(r) }\n        }\n    }()\n    return validate.Struct(s)\n}","preventionTips":["Never build validate tags with Sprintf on possibly-empty variables","Strip empty segments when generating tags programmatically","Check aliases for empty expansions","Fail fast with an init-time validation of every struct type"],"tags":["go","validator","panic","tag-syntax","cache"],"backgroundTag":"validator-invalid-tag-syntax","analyzedSha":"facf128d2eecf42bd4ff447adc961aa21bb64aed","analyzedAt":"2026-09-02T10:19:04.986Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T16:17:10.729Z"}