{"record":{"id":"3c038d4b29147a52","repo":"apache/answer","slug":"validate-check-exception","errorCode":null,"errorMessage":"validate check exception","messagePattern":"validate check exception","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/base/validator/validator.go","lineNumber":215,"sourceCode":"\t\t\t\tcontinue\n\t\t\t}\n\t\t\tfirstRune := []rune(field.ErrorMsg)[0]\n\t\t\tif !unicode.IsLetter(firstRune) || !unicode.Is(unicode.Latin, firstRune) {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tupperFirstRune := unicode.ToUpper(firstRune)\n\t\t\tfield.ErrorMsg = string(upperFirstRune) + field.ErrorMsg[1:]\n\t\t\tif !strings.HasSuffix(field.ErrorMsg, \".\") {\n\t\t\t\tfield.ErrorMsg += \".\"\n\t\t\t}\n\t\t}\n\t}()\n\terr = m.Validate.Struct(value)\n\tif err != nil {\n\t\tvar valErrors validator.ValidationErrors\n\t\tif !errors.As(err, &valErrors) {\n\t\t\tlog.Error(err)\n\t\t\treturn nil, errors.New(\"validate check exception\")\n\t\t}\n\n\t\tfor _, fieldError := range valErrors {\n\t\t\terrField := &FormErrorField{\n\t\t\t\tErrorField: fieldError.Field(),\n\t\t\t\tErrorMsg:   fieldError.Translate(m.Tran),\n\t\t\t}\n\n\t\t\t// get original tag name from value for set err field key.\n\t\t\tstructNamespace := fieldError.StructNamespace()\n\t\t\t_, fieldName, found := strings.Cut(structNamespace, \".\")\n\t\t\tif found {\n\t\t\t\toriginalTag := getObjectTagByFieldName(value, fieldName)\n\t\t\t\tif len(originalTag) > 0 {\n\t\t\t\t\terrField.ErrorField = originalTag\n\t\t\t\t}\n\t\t\t}\n\t\t\terrFields = append(errFields, errField)","sourceCodeStart":197,"sourceCodeEnd":233,"githubUrl":"https://github.com/apache/answer/blob/3b9f1370612e690a0b7f230f05e688930db4c6d3/internal/base/validator/validator.go#L197-L233","documentation":"Check runs the go-playground/validator Struct validation on a model and translates field errors into FormErrorField entries. If the returned error is NOT a validator.ValidationErrors (i.e. an unexpected internal validator failure such as a bad tag or wrong input type), it logs and returns the generic 'validate check exception'.","triggerScenarios":"Passing a value whose type validator can't struct-validate (non-struct, nil pointer misfire, map without register), or a struct with an invalid/misconfigured validate tag that makes the validator return a non-ValidationErrors error.","commonSituations":"Developer adds a custom validator tag without registering it, misuses tags like `validate:\"-\"` incorrectly, passes a non-struct to Check, or upgrades go-playground/validator causing tag incompatibilities.","solutions":["Inspect the server log above this error — the underlying validator error is logged via log.Error(err).","Fix the struct's validate tags (e.g. register missing custom validators with validator.RegisterValidation).","Ensure the value passed to Check is a struct or pointer to struct.","Pin/align the go-playground/validator version and the translator setup."],"exampleFix":"// before\nAnswer `validate:\"omitempty,unknown_rule\"`\n// after\nAnswer string `validate:\"omitempty,min=1,max=500\"`","handlingStrategy":"validation","validationCode":"v := validator.New()\nv.RegisterTagNameFunc(func(fld reflect.StructField) string { return fld.Tag.Get(\"json\") })\nif err := v.Struct(MyRequest{}); err != nil {\n  var ve validator.ValidationErrors\n  if !errors.As(err, &ve) { log.Fatalf(\"validator misconfigured: %v\", err) }\n}","typeGuard":"func isStructPtr(v any) bool {\n  rv := reflect.ValueOf(v)\n  return rv.Kind() == reflect.Ptr && rv.Elem().Kind() == reflect.Struct\n}","tryCatchPattern":"form, err := validator.Check(req)\nif err != nil {\n  if err.Error() == \"validate check exception\" {\n    log.Errorf(\"validator internal failure: %v\", err)\n    return 500 // not a user input problem\n  }\n}","preventionTips":["Only pass structs (or struct pointers) to Check","Register every custom validator tag you use in tags","Validate tag syntax in unit tests for request structs","Keep go-playground/validator and translator deps aligned"],"tags":["validation","go","go-playground-validator"],"backgroundTag":"schema-validation-failed","analyzedSha":"3b9f1370612e690a0b7f230f05e688930db4c6d3","analyzedAt":"2026-09-05T18:18:39.533Z","contentChangedAt":"2026-09-05T18:18:39.533Z","schemaVersion":2},"datasetVersion":"2026-09-12T22:17:10.623Z"}