{"id":"32a8eaa4b25b8432","repo":"labstack/echo","slug":"errvalidatornotregistered","errorCode":"ErrValidatorNotRegistered","errorMessage":"validator not registered","messagePattern":"validator not registered","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"httperror.go","lineNumber":30,"sourceCode":"// The following errors can produce HTTP status code by implementing HTTPStatusCoder interface\nvar (\n\tErrBadRequest                  = &httpError{http.StatusBadRequest}            // 400\n\tErrUnauthorized                = &httpError{http.StatusUnauthorized}          // 401\n\tErrForbidden                   = &httpError{http.StatusForbidden}             // 403\n\tErrNotFound                    = &httpError{http.StatusNotFound}              // 404\n\tErrMethodNotAllowed            = &httpError{http.StatusMethodNotAllowed}      // 405\n\tErrRequestTimeout              = &httpError{http.StatusRequestTimeout}        // 408\n\tErrStatusRequestEntityTooLarge = &httpError{http.StatusRequestEntityTooLarge} // 413\n\tErrUnsupportedMediaType        = &httpError{http.StatusUnsupportedMediaType}  // 415\n\tErrTooManyRequests             = &httpError{http.StatusTooManyRequests}       // 429\n\tErrInternalServerError         = &httpError{http.StatusInternalServerError}   // 500\n\tErrBadGateway                  = &httpError{http.StatusBadGateway}            // 502\n\tErrServiceUnavailable          = &httpError{http.StatusServiceUnavailable}    // 503\n)\n\n// The following errors fall into 500 (InternalServerError) category\nvar (\n\tErrValidatorNotRegistered = errors.New(\"validator not registered\")\n\tErrRendererNotRegistered  = errors.New(\"renderer not registered\")\n\tErrInvalidRedirectCode    = errors.New(\"invalid redirect status code\")\n\tErrCookieNotFound         = errors.New(\"cookie not found\")\n\tErrInvalidCertOrKeyType   = errors.New(\"invalid cert or key type, must be string or []byte\")\n\tErrInvalidListenerNetwork = errors.New(\"invalid listener network\")\n)\n\n// HTTPStatusCoder is an interface that errors can implement to produce status code for HTTP response\ntype HTTPStatusCoder interface {\n\tStatusCode() int\n}\n\n// StatusCode returns status code from err if it implements HTTPStatusCoder interface.\n// If err does not implement the interface, it returns 0.\nfunc StatusCode(err error) int {\n\tvar sc HTTPStatusCoder\n\tif errors.As(err, &sc) {\n\t\treturn sc.StatusCode()","sourceCodeStart":12,"sourceCodeEnd":48,"githubUrl":"https://github.com/labstack/echo/blob/05489dc1730161df26b72d1ae2a3ba6fb8178fc7/httperror.go#L12-L48","documentation":"ErrValidatorNotRegistered is returned by Context.Validate when c.echo.Validator is nil. Validate delegates to the registered Validator interface; with nothing registered there is no validation logic to run, so Echo refuses rather than silently passing validation.","triggerScenarios":"Calling c.Validate(obj) in a handler without first setting e.Validator = &CustomValidator{} on the Echo instance. Common when following a tutorial that adds c.Validate calls but skips the validator registration step.","commonSituations":"Forgetting to register the validator in main.go. Using a different Echo instance for testing than the one configured with the validator. Removing the validator registration during a refactor.","solutions":["Register a validator: e.Validator = &myValidator{} where myValidator implements echo.Validator (Validate(any) error)","Use the popular go-playground/validator wrapper (echo-contrib echovault or custom adapter)","Guard handler code: only call c.Validate if e.Validator != nil"],"exampleFix":"// before — handler calls Validate but no validator registered\ne := echo.New()\ne.GET(\"/u\", func(c echo.Context) error {\n    u := new(User)\n    c.Bind(u)\n    return c.Validate(u) // ErrValidatorNotRegistered\n})\n\n// after\ne := echo.New()\ne.Validator = &CustomValidator{validator: validate.New()}","handlingStrategy":"validation","validationCode":"// Guard Validate calls\nif c.Echo().Validator != nil {\n    if err := c.Validate(obj); err != nil {\n        return err\n    }\n}","typeGuard":null,"tryCatchPattern":"if err := c.Validate(obj); err != nil {\n    if errors.Is(err, echo.ErrValidatorNotRegistered) {\n        // validation skipped; proceed or log a warning\n        return nil\n    }\n    return echo.NewHTTPError(http.StatusBadRequest, err.Error())\n}","preventionTips":["Register the validator once at startup: e.Validator = &myValidator{}","Add a startup assertion: if e.Validator == nil { log.Fatal(\"validator not set\") }","Write an integration test that calls c.Validate to catch registration issues in CI"],"tags":["validation","configuration","startup"],"analyzedSha":"05489dc1730161df26b72d1ae2a3ba6fb8178fc7","analyzedAt":"2026-08-04T21:32:47.783Z","schemaVersion":2}