{"id":"54491081519f3c41","repo":"labstack/echo","slug":"errcookienotfound","errorCode":"ErrCookieNotFound","errorMessage":"cookie not found","messagePattern":"cookie not found","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"httperror.go","lineNumber":33,"sourceCode":"\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()\n\t}\n\treturn 0\n}","sourceCodeStart":15,"sourceCodeEnd":51,"githubUrl":"https://github.com/labstack/echo/blob/05489dc1730161df26b72d1ae2a3ba6fb8178fc7/httperror.go#L15-L51","documentation":"ErrCookieNotFound is an exported sentinel error representing a missing cookie. Note that Context.Cookie delegates to the standard library http.Request.Cookie, which returns http.ErrNoCookie; Echo provides this sentinel as a semantic alternative for user code and middleware that wish to use Echo's error vocabulary. Middleware like CSRF check c.Cookie and compare against this error shape.","triggerScenarios":"Calling c.Cookie(\"session\") when the request contains no Cookie header with that name. The underlying stdlib returns http.ErrNoCookie; user code may compare against echo.ErrCookieNotFound when using Echo idioms.","commonSituations":"First-time visitor with no session cookie. Cookie name mismatch (e.g. case sensitivity, trailing whitespace). Cookie expired and browser stopped sending it.","solutions":["Check the returned error and handle the missing-cookie case gracefully (redirect to login, set a new cookie)","Iterate c.Cookies() to see all available cookies for debugging name mismatches","Use errors.Is(err, http.ErrNoCookie) since Context.Cookie returns the stdlib error"],"exampleFix":"// before\ncookie, err := c.Cookie(\"session\")\nif err == echo.ErrCookieNotFound { ... } // may not match stdlib error\n\n// after\ncookie, err := c.Cookie(\"session\")\nif errors.Is(err, http.ErrNoCookie) {\n    return c.Redirect(http.StatusFound, \"/login\")\n}","handlingStrategy":"try-catch","validationCode":"// Check cookie presence via Cookies() slice before Cookie()\nfunc hasCookie(c echo.Context, name string) bool {\n    for _, ck := range c.Cookies() {\n        if ck.Name == name { return true }\n    }\n    return false\n}","typeGuard":null,"tryCatchPattern":"cookie, err := c.Cookie(\"session\")\nif err != nil {\n    if errors.Is(err, http.ErrNoCookie) {\n        return c.Redirect(http.StatusFound, \"/login\")\n    }\n    return err\n}","preventionTips":["Always check the error from c.Cookie and handle the missing case explicitly","Use c.Cookies() to enumerate available cookies when debugging name mismatches","Standardize cookie names as constants shared between writer and reader code"],"tags":["cookie","http-request","sentinel-error"],"analyzedSha":"05489dc1730161df26b72d1ae2a3ba6fb8178fc7","analyzedAt":"2026-08-04T21:32:47.783Z","schemaVersion":2}