gocolly/colly · error
ErrNoCookieJar
ErrNoCookieJar
Error message
Cookie jar is not available
What it means
ErrNoCookieJar is returned when the collector is configured with cookies (e.g. c.SetCookies or cookie-dependent flows) but no cookie jar has been attached via c.SetCookieJar. Colly does not install a default jar; without one it cannot store or send cookies, so cookie operations fail with this error.
Source
Thrown at colly.go:238
var (
// ErrForbiddenDomain is the error thrown if visiting
// a domain which is not allowed in AllowedDomains
ErrForbiddenDomain = errors.New("Forbidden domain")
// ErrMissingURL is the error type for missing URL errors
ErrMissingURL = errors.New("Missing URL")
// ErrMaxDepth is the error type for exceeding max depth
ErrMaxDepth = errors.New("Max depth limit reached")
// ErrForbiddenURL is the error thrown if visiting
// a URL which is not allowed by URLFilters
ErrForbiddenURL = errors.New("ForbiddenURL")
// ErrNoURLFiltersMatch is the error thrown if visiting
// a URL which is not allowed by URLFilters
ErrNoURLFiltersMatch = errors.New("No URLFilters match")
// ErrRobotsTxtBlocked is the error type for robots.txt errors
ErrRobotsTxtBlocked = errors.New("URL blocked by robots.txt")
// ErrNoCookieJar is the error type for missing cookie jar
ErrNoCookieJar = errors.New("Cookie jar is not available")
// ErrNoPattern is the error type for LimitRules without patterns
ErrNoPattern = errors.New("No pattern defined in LimitRule")
// ErrEmptyProxyURL is the error type for empty Proxy URL list
ErrEmptyProxyURL = errors.New("Proxy URL list is empty")
// ErrAbortedAfterHeaders is the error returned when OnResponseHeaders aborts the transfer.
ErrAbortedAfterHeaders = errors.New("Aborted after receiving response headers")
// ErrAbortedBeforeRequest is the error returned when OnResponseHeaders aborts the transfer.
ErrAbortedBeforeRequest = errors.New("Aborted before Do Request")
// ErrQueueFull is the error returned when the queue is full
ErrQueueFull = errors.New("Queue MaxSize reached")
// ErrMaxRequests is the error returned when exceeding max requests
ErrMaxRequests = errors.New("Max Requests limit reached")
// ErrRetryBodyUnseekable is the error when retry with not seekable body
ErrRetryBodyUnseekable = errors.New("Retry Body Unseekable")
)
var envMap = map[string]func(*Collector, string){
"ALLOWED_DOMAINS": func(c *Collector, val string) {View on GitHub (pinned to 17d1d6ca92)
Solutions
- Attach a jar before any cookie-dependent call: c.SetCookieJar(jar)
- Use a standard jar: jar, _ := cookiejar.New(nil); c.SetCookieJar(jar)
- If cookies are unnecessary, avoid SetCookies/cookie APIs entirely
- If you rely on an underlying http.Client, ensure the jar is set on that client and passed to the collector
Example fix
// before c := colly.NewCollector() c.SetCookies(u, cookies) // ErrNoCookieJar // after import "net/http/cookiejar" c := colly.NewCollector() jar, _ := cookiejar.New(nil) c.SetCookieJar(jar) c.SetCookies(u, cookies)
Defensive patterns
Strategy: validation
Validate before calling
jar, err := cookiejar.New(nil)
if err != nil {
return err
}
c.SetCookieJar(jar) // do this before any cookie-dependent call Try / catch
if err := c.SetCookies(u, cookies); err != nil && errors.Is(err, colly.ErrNoCookieJar) {
jar, _ := cookiejar.New(nil)
c.SetCookieJar(jar)
return c.SetCookies(u, cookies)
} Prevention
- Always attach a cookiejar in collector bootstrap code
- Set the jar before any login/cookie flows, not on demand
- If using a custom http.Client, share its jar with the collector
When it happens
Trigger: Calling c.SetCookies(u, cookies) (or relying on automatic cookie persistence) before calling c.SetCookieJar(jar); creating a collector and doing authenticated multi-request flows without attaching a jar; copying collector config but dropping the jar assignment.
Common situations: Login-then-scrape flows where the session cookie must persist between requests; reusing http.Client cookie jars across collectors incorrectly; forgetting that Colly's default collector has no jar even though net/http clients often do.
Related errors
AI-assisted analysis of gocolly/colly@17d1d6ca92 (2026-08-30).
Data as JSON: /api/errors/fe915455f435368b.
Report an issue: GitHub.