{"record":{"id":"f547206ba0ec7b33","repo":"gocolly/colly","slug":"errabortedbeforerequest","errorCode":"ErrAbortedBeforeRequest","errorMessage":"Aborted before Do Request","messagePattern":"Aborted before Do Request","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"colly.go","lineNumber":246,"sourceCode":"\t// ErrForbiddenURL is the error thrown if visiting\n\t// a URL which is not allowed by URLFilters\n\tErrForbiddenURL = errors.New(\"ForbiddenURL\")\n\n\t// ErrNoURLFiltersMatch is the error thrown if visiting\n\t// a URL which is not allowed by URLFilters\n\tErrNoURLFiltersMatch = errors.New(\"No URLFilters match\")\n\t// ErrRobotsTxtBlocked is the error type for robots.txt errors\n\tErrRobotsTxtBlocked = errors.New(\"URL blocked by robots.txt\")\n\t// ErrNoCookieJar is the error type for missing cookie jar\n\tErrNoCookieJar = errors.New(\"Cookie jar is not available\")\n\t// ErrNoPattern is the error type for LimitRules without patterns\n\tErrNoPattern = errors.New(\"No pattern defined in LimitRule\")\n\t// ErrEmptyProxyURL is the error type for empty Proxy URL list\n\tErrEmptyProxyURL = errors.New(\"Proxy URL list is empty\")\n\t// ErrAbortedAfterHeaders is the error returned when OnResponseHeaders aborts the transfer.\n\tErrAbortedAfterHeaders = errors.New(\"Aborted after receiving response headers\")\n\t// ErrAbortedBeforeRequest is the error returned when OnResponseHeaders aborts the transfer.\n\tErrAbortedBeforeRequest = errors.New(\"Aborted before Do Request\")\n\t// ErrQueueFull is the error returned when the queue is full\n\tErrQueueFull = errors.New(\"Queue MaxSize reached\")\n\t// ErrMaxRequests is the error returned when exceeding max requests\n\tErrMaxRequests = errors.New(\"Max Requests limit reached\")\n\t// ErrRetryBodyUnseekable is the error when retry with not seekable body\n\tErrRetryBodyUnseekable = errors.New(\"Retry Body Unseekable\")\n)\n\nvar envMap = map[string]func(*Collector, string){\n\t\"ALLOWED_DOMAINS\": func(c *Collector, val string) {\n\t\tc.AllowedDomains = strings.Split(val, \",\")\n\t},\n\t\"CACHE_DIR\": func(c *Collector, val string) {\n\t\tc.CacheDir = val\n\t},\n\t\"DETECT_CHARSET\": func(c *Collector, val string) {\n\t\tc.DetectCharset = isYesString(val)\n\t},","sourceCodeStart":228,"sourceCodeEnd":264,"githubUrl":"https://github.com/gocolly/colly/blob/17d1d6ca92bd32a5651f34256bf7a2855c967f65/colly.go#L228-L264","documentation":"ErrAbortedBeforeRequest is returned by the HTTP backend's Do method (http_backend.go) when a pre-flight request-header check returns false — i.e. a checkRequestHeaders callback (installed by the collector) aborted the transfer before the request was sent. It signals that the request never left the client; the abort happened in user code via a header-check hook. The error variable is declared in colly.go:246 alongside the other sentinel errors.","triggerScenarios":"A checkRequestHeaders callback (set through the collector's request-header check hook) returns false, causing http_backend.Do to return ErrAbortedBeforeRequest instead of performing the HTTP request.","commonSituations":"Developers install a header-check callback to filter out requests (e.g. dropping requests missing an auth header or to certain hosts) and forget that returning false surfaces as this error; it is also hit when callback logic aborts unintentionally on edge cases like empty URLs or stripped headers.","solutions":["Inspect your request-header check callback and make sure returning false is intentional for the request in question","Log the request URL/headers inside the callback to see which request is being aborted","If the request should proceed, fix the callback condition so it returns true","Compare the error with errors.Is(err, colly.ErrAbortedBeforeRequest) to handle aborts distinctly from network failures"],"exampleFix":"// before: callback aborts everything\nfunc(r *http.Request) bool { return strings.HasPrefix(r.Header.Get(\"Authorization\"), \"Bearer\") }\n// after: only abort when auth is required\nfunc(r *http.Request) bool { return !strings.Contains(r.URL.Host, \"public.example.com\") }","handlingStrategy":"try-catch","validationCode":"// ensure the header-check callback admits this request before sending\nif !headerCheckAllows(req) {\n    // skip or log instead of letting the backend abort\n}","typeGuard":"func isAbortedBeforeRequest(err error) bool { return errors.Is(err, colly.ErrAbortedBeforeRequest) }","tryCatchPattern":"if err := c.Visit(url); err != nil {\n    if errors.Is(err, colly.ErrAbortedBeforeRequest) {\n        log.Printf(\"request aborted by header check: %s\", url)\n        return nil // intentional skip\n    }\n    return err\n}","preventionTips":["Keep header-check callbacks pure and simple; log every false return","Unit-test the callback against representative requests","Use errors.Is against the sentinel rather than string comparison","Document which requests the callback is meant to abort"],"tags":["http","request-aborted","colly"],"backgroundTag":"request-aborted-by-callback","analyzedSha":"17d1d6ca92bd32a5651f34256bf7a2855c967f65","analyzedAt":"2026-08-30T21:32:31.579Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}