labstack/echo · error
ErrValidatorNotRegistered
ErrValidatorNotRegistered
Error message
validator not registered
What it means
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.
Source
Thrown at httperror.go:30
// The following errors can produce HTTP status code by implementing HTTPStatusCoder interface
var (
ErrBadRequest = &httpError{http.StatusBadRequest} // 400
ErrUnauthorized = &httpError{http.StatusUnauthorized} // 401
ErrForbidden = &httpError{http.StatusForbidden} // 403
ErrNotFound = &httpError{http.StatusNotFound} // 404
ErrMethodNotAllowed = &httpError{http.StatusMethodNotAllowed} // 405
ErrRequestTimeout = &httpError{http.StatusRequestTimeout} // 408
ErrStatusRequestEntityTooLarge = &httpError{http.StatusRequestEntityTooLarge} // 413
ErrUnsupportedMediaType = &httpError{http.StatusUnsupportedMediaType} // 415
ErrTooManyRequests = &httpError{http.StatusTooManyRequests} // 429
ErrInternalServerError = &httpError{http.StatusInternalServerError} // 500
ErrBadGateway = &httpError{http.StatusBadGateway} // 502
ErrServiceUnavailable = &httpError{http.StatusServiceUnavailable} // 503
)
// The following errors fall into 500 (InternalServerError) category
var (
ErrValidatorNotRegistered = errors.New("validator not registered")
ErrRendererNotRegistered = errors.New("renderer not registered")
ErrInvalidRedirectCode = errors.New("invalid redirect status code")
ErrCookieNotFound = errors.New("cookie not found")
ErrInvalidCertOrKeyType = errors.New("invalid cert or key type, must be string or []byte")
ErrInvalidListenerNetwork = errors.New("invalid listener network")
)
// HTTPStatusCoder is an interface that errors can implement to produce status code for HTTP response
type HTTPStatusCoder interface {
StatusCode() int
}
// StatusCode returns status code from err if it implements HTTPStatusCoder interface.
// If err does not implement the interface, it returns 0.
func StatusCode(err error) int {
var sc HTTPStatusCoder
if errors.As(err, &sc) {
return sc.StatusCode()View on GitHub (pinned to 05489dc173)
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
Example fix
// before — handler calls Validate but no validator registered
e := echo.New()
e.GET("/u", func(c echo.Context) error {
u := new(User)
c.Bind(u)
return c.Validate(u) // ErrValidatorNotRegistered
})
// after
e := echo.New()
e.Validator = &CustomValidator{validator: validate.New()} Defensive patterns
Strategy: validation
Validate before calling
// Guard Validate calls
if c.Echo().Validator != nil {
if err := c.Validate(obj); err != nil {
return err
}
} Try / catch
if err := c.Validate(obj); err != nil {
if errors.Is(err, echo.ErrValidatorNotRegistered) {
// validation skipped; proceed or log a warning
return nil
}
return echo.NewHTTPError(http.StatusBadRequest, err.Error())
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- echo basic-auth middleware requires a validator function
- echo body-dump middleware requires a handler function
- invalid gzip level
- panic: err from config.ToMiddleware() in RequestLoggerWithCo
- ErrInvalidRedirectCode
AI-assisted analysis of labstack/echo@05489dc173 (2026-08-04).
Data as JSON: /data/errors/32a8eaa4b25b8432.json.
Report an issue: GitHub.