{"record":{"id":"044feda6478f75e8","repo":"valyala/fasthttp","slug":"fasthttp-no-cookies-found","errorCode":null,"errorMessage":"fasthttp: no cookies found","messagePattern":"fasthttp: no cookies found","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"info","filePath":"cookie.go","lineNumber":379,"sourceCode":"\tc.bufK = c.AppendBytes(c.bufK[:0])\n\treturn c.bufK\n}\n\n// String returns cookie representation.\nfunc (c *Cookie) String() string {\n\treturn string(c.Cookie())\n}\n\n// WriteTo writes cookie representation to w.\n//\n// WriteTo implements io.WriterTo interface.\nfunc (c *Cookie) WriteTo(w io.Writer) (int64, error) {\n\tn, err := w.Write(c.Cookie())\n\treturn int64(n), err\n}\n\nvar (\n\tErrNoCookies          = errors.New(\"fasthttp: no cookies found\")\n\tErrInvalidCookieValue = errors.New(\"fasthttp: invalid cookie value\")\n)\n\n// Parse parses Set-Cookie header.\nfunc (c *Cookie) Parse(src string) error {\n\tc.bufK = append(c.bufK[:0], src...)\n\treturn c.ParseBytes(c.bufK)\n}\n\n// ParseBytes parses Set-Cookie header.\nfunc (c *Cookie) ParseBytes(src []byte) error {\n\tc.Reset()\n\n\tvar s cookieScanner\n\ts.b = src\n\n\tvar k, v []byte\n\tif !s.nextRaw(&k, &v) {","sourceCodeStart":361,"sourceCodeEnd":397,"githubUrl":"https://github.com/valyala/fasthttp/blob/c96f600972c6f4a7a30d664257b340ebe9d60124/cookie.go#L361-L397","documentation":"ErrNoCookies is returned by Response/Header & Cookie parsing helpers when scanning a Cookie header finds no valid cookies at all. The library distinguishes 'nothing to parse' from 'malformed value'. It signals an empty or entirely invalid cookie list.","triggerScenarios":"Calling Response.Header.Cookies() / Response.Header.peek of Cookie header when the request/response carries no Cookie header or only whitespace; iterating cookies over an empty header.","commonSituations":"First request of a session with no cookies set yet; proxies stripping Cookie headers; code assuming cookies always exist after a redirect.","solutions":["Check whether the Cookie header exists before parsing cookies","Treat ErrNoCookies as 'no session yet' and proceed to login/set-cookie flow","Guard iteration with a len check on the raw header value"],"exampleFix":"// before\ncookies := resp.Header.Cookies() // may return ErrNoCookies\n// after\nif len(resp.Header.Peek(\"Cookie\")) == 0 {\n    return nil // no cookies yet, skip parsing\n}\ncookies := resp.Header.Cookies()","handlingStrategy":"type-guard","validationCode":"if len(resp.Header.Peek(\"Cookie\")) == 0 {\n    return nil // nothing to parse\n}","typeGuard":"func hasCookies(h *fasthttp.ResponseHeader) bool {\n    return len(h.Peek(\"Cookie\")) > 0\n}","tryCatchPattern":"if err := parseCookies(h); errors.Is(err, fasthttp.ErrNoCookies) {\n    return cookieSet{} // empty set is fine\n}","preventionTips":["Check for a Cookie header before iterating cookies","Model 'no cookies' as an empty set, not an error path","Set cookies explicitly on first request of a session"],"tags":["fasthttp","cookies","parsing"],"backgroundTag":"no-cookies-found","analyzedSha":"c96f600972c6f4a7a30d664257b340ebe9d60124","analyzedAt":"2026-08-31T22:48:28.265Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}