gocolly/colly · warning
ErrNoPattern
ErrNoPattern
Error message
No pattern defined in LimitRule
What it means
ErrNoPattern is returned by LimitRule.Init() when a LimitRule has no URL pattern defined. Limit rules use regexp patterns to match which URLs a rate limit applies to; a rule without DomainRegexp, Domain, or URLRegexp/Path cannot be compiled, so Init fails and the collector cannot start limiting.
Source
Thrown at colly.go:240
// 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) {
c.AllowedDomains = strings.Split(val, ",")
},View on GitHub (pinned to 17d1d6ca92)
Solutions
- Set a pattern on the rule: Domain, DomainRegexp, or URLRegexp must be non-empty
- Validate rule config at startup before calling c.LimitRule
- Skip empty rules in generated config instead of passing them to LimitRule
- Double-check field names — pattern fields are DomainRegexp/DomainGlob/URLRegexp etc., not "Pattern"
Example fix
// before
rule := &colly.LimitRule{Delay: 2 * time.Second, RandomDelay: time.Second}
err := c.LimitRule(rule) // ErrNoPattern: no pattern defined
// after
rule := &colly.LimitRule{DomainRegexp: "example\.com", Delay: 2 * time.Second, RandomDelay: time.Second}
err := c.LimitRule(rule) Defensive patterns
Strategy: validation
Validate before calling
for _, r := range rules {
if r.Domain == "" && r.DomainRegexp == "" && r.DomainGlob == "" && r.URLRegexp == "" {
return fmt.Errorf("limit rule %+v has no pattern", r)
}
}
for _, r := range rules {
if err := c.LimitRule(r); err != nil { return err }
} Try / catch
if err := c.LimitRule(rule); err != nil {
if errors.Is(err, colly.ErrNoPattern) {
return fmt.Errorf("rule %v missing Domain/DomainRegexp/URLRegexp: %w", rule, err)
}
return err
} Prevention
- Validate rule config (patterns non-empty) before LimitRule calls
- Keep limit rules in reviewed config files, not ad-hoc literals
- Skip or reject empty generated rules instead of passing them through
When it happens
Trigger: Calling c.LimitRule(&colly.LimitRule{DomainRegexp: "...", Delay: ...}) with a rule missing any pattern fields; constructing rules dynamically where the pattern string ends up empty; c.Limit/rules initialization loops where one entry forgot its pattern.
Common situations: Building LimitRules from config/JSON where the pattern key is absent or empty; copy-pasting a rule and deleting the Domain/DomainRegexp line; programmatically generating rules for multiple domains where one domain string is blank.
Related errors
AI-assisted analysis of gocolly/colly@17d1d6ca92 (2026-08-30).
Data as JSON: /api/errors/c6d4d6b7f44998be.
Report an issue: GitHub.