{"record":{"id":"90ea4d7fc3403b3f","repo":"projectdiscovery/katana","slug":"create-task-w","errorCode":null,"errorMessage":"create task: %w","messagePattern":"create task: %w","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/engine/headless/captcha/capsolver/capsolver.go","lineNumber":70,"sourceCode":"\nfunc (s *Solver) Solve(ctx context.Context, info *captcha.Info) (*captcha.Solution, error) {\n\ttaskType, ok := taskTypes[info.Provider]\n\tif !ok {\n\t\treturn nil, fmt.Errorf(\"unsupported captcha provider for capsolver: %s\", info.Provider)\n\t}\n\n\ttask := map[string]any{\n\t\t\"type\":       taskType,\n\t\t\"websiteURL\": info.PageURL,\n\t\t\"websiteKey\": info.SiteKey,\n\t}\n\tif (info.Provider == captcha.ProviderRecaptchaV3 || info.Provider == captcha.ProviderRecaptchaV3Enterprise) && info.Action != \"\" {\n\t\ttask[\"pageAction\"] = info.Action\n\t}\n\n\ttaskID, err := s.createTask(ctx, task)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"create task: %w\", err)\n\t}\n\n\treturn s.pollResult(ctx, taskID, info.Provider)\n}\n\ntype createTaskRequest struct {\n\tClientKey string         `json:\"clientKey\"`\n\tTask      map[string]any `json:\"task\"`\n}\n\ntype createTaskResponse struct {\n\tErrorID          int    `json:\"errorId\"`\n\tErrorCode        string `json:\"errorCode\"`\n\tErrorDescription string `json:\"errorDescription\"`\n\tTaskID           string `json:\"taskId\"`\n}\n\ntype getTaskResultRequest struct {","sourceCodeStart":52,"sourceCodeEnd":88,"githubUrl":"https://github.com/projectdiscovery/katana/blob/e3e742739c3746f085943ce918fb4e2b8daf6fe6/pkg/engine/headless/captcha/capsolver/capsolver.go#L52-L88","documentation":"capsolver.Solver.Solve wraps any error from createTask (its POST to https://api.capsolver.com/createTask) with the 'create task: %w' prefix. Underlying causes include network failures, non-JSON responses, JSON decode errors, and capsolver API errors (which surface as the separate 'capsolver error' message).","triggerScenarios":"Solve(ctx, info) with a valid provider, where s.createTask fails: HTTP request error (network/DNS/timeout via the 30s client), non-2xx or non-JSON response body, json.Unmarshal failure on the response, or an API error response.","commonSituations":"Invalid or expired capsolver API key (errorId != 0 wrapped here); network egress blocked by firewall/proxy; capsolver outage returning HTML error pages; context deadline exceeded while posting; self-hosted capsolver proxy misconfigured via SetBaseURL.","solutions":["Unwrap the error (%w) to see the root cause and check whether it's a capsolver API error (errorId/errorCode) vs a network error.","Verify the capsolver API key is valid and has balance — auth/billing errors surface here.","Check network connectivity/proxy settings and that api.capsolver.com (or the custom SetBaseURL) is reachable.","Retry with backoff for transient network/5xx failures; respect context cancellation.","Log the raw response body when unmarshalling fails to detect non-JSON outage responses."],"exampleFix":"// before\nsol, err := solver.Solve(ctx, info)\nif err != nil {\n    return fmt.Errorf(\"captcha solve failed: %v\", err)\n}\n// after\nsol, err := solver.Solve(ctx, info)\nif err != nil {\n    var apiErr *captcha.APIError\n    if errors.As(err, &apiErr) {\n        return fmt.Errorf(\"capsolver rejected task: %s\", apiErr.Code) // no blind retry\n    }\n    if errors.Is(err, context.DeadlineExceeded) {\n        return err // surface timeout, do not retry hung context\n    }\n    return retry.WithBackoff(func() (*captcha.Solution, error) { return solver.Solve(ctx, info) })\n}","handlingStrategy":"retry","validationCode":"// before solving\nif apiKey == \"\" { return errors.New(\"capsolver API key required\") }\nif info.PageURL == \"\" || info.SiteKey == \"\" { return errors.New(\"captcha info incomplete\") }\nif err := ctx.Err(); err != nil { return err }","typeGuard":null,"tryCatchPattern":"sol, err := solver.Solve(ctx, info)\nif err != nil {\n    if strings.HasPrefix(err.Error(), \"create task: capsolver error\") {\n        return nil, err // API rejection: do not retry\n    }\n    if errors.Is(err, context.DeadlineExceeded) || isNetworkErr(err) {\n        return retryWithBackoff(func() (*captcha.Solution, error) { return solver.Solve(ctx, info) }, 3)\n    }\n    return nil, err\n}","preventionTips":["Validate API key and captcha Info fields before calling Solve","Distinguish API rejections (non-retryable) from network failures (retryable) via error unwrapping","Set generous context timeouts; the solver itself polls up to 120s","Monitor capsolver status/outages and configure a fallback solver backend"],"tags":["captcha","capsolver","api","network","go"],"backgroundTag":"captcha-api-request-failed","analyzedSha":"e3e742739c3746f085943ce918fb4e2b8daf6fe6","analyzedAt":"2026-09-03T14:55:13.248Z","contentChangedAt":"2026-09-03T14:55:13.248Z","schemaVersion":2},"datasetVersion":"2026-09-10T17:17:09.494Z"}