{"record":{"id":"a6535d909f1300bc","repo":"fish2018/pansou","slug":"cloudscraper-not-initialized-a6535d","errorCode":null,"errorMessage":"cloudscraper not initialized","messagePattern":"cloudscraper not initialized","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"plugin/panzun/panzun.go","lineNumber":110,"sourceCode":"\t\t},\n\t}\n}\n\nfunc (p *PanzunPlugin) Search(keyword string, ext map[string]interface{}) ([]model.SearchResult, error) {\n\tresult, err := p.SearchWithResult(keyword, ext)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\treturn result.Results, nil\n}\n\nfunc (p *PanzunPlugin) SearchWithResult(keyword string, ext map[string]interface{}) (model.PluginSearchResult, error) {\n\treturn p.AsyncSearchWithResult(keyword, p.searchImpl, p.MainCacheKey, ext)\n}\n\nfunc (p *PanzunPlugin) searchImpl(client *http.Client, keyword string, ext map[string]interface{}) ([]model.SearchResult, error) {\n\tif p.scraper == nil {\n\t\treturn nil, fmt.Errorf(\"cloudscraper not initialized\")\n\t}\n\n\tvar allResults []model.SearchResult\n\tseenIDs := make(map[string]bool)\n\n\tfor page := 1; page <= maxPages; page++ {\n\t\toffset := (page - 1) * pageSize\n\t\tsearchURL := fmt.Sprintf(\"%s/discussions?filter[q]=%s&page[offset]=%d\", apiBase, url.QueryEscape(keyword), offset)\n\n\t\tresp, err := p.scraper.Get(searchURL)\n\t\tif err != nil {\n\t\t\tif len(allResults) > 0 {\n\t\t\t\tfmt.Printf(\"[%s] Warning: failed to fetch page %d: %v\\n\", p.Name(), page, err)\n\t\t\t\tbreak\n\t\t\t}\n\t\t\treturn nil, fmt.Errorf(\"[%s] search request failed on page %d: %w\", p.Name(), page, err)\n\t\t}\n","sourceCodeStart":92,"sourceCodeEnd":128,"githubUrl":"https://github.com/fish2018/pansou/blob/beaa56133755a548ebc51b090b3816e2ae044aa6/plugin/panzun/panzun.go#L92-L128","documentation":"PanzunPlugin.searchImpl returns this error when the plugin's cloudscraper client (p.scraper) is still nil when a search is executed. The scraper must be created during plugin construction (NewPanzunPlugin) before AsyncSearchWithResult dispatches searchImpl in a worker. A nil scraper means every HTTP request would panic, so the code fails fast with this sentinel error.","triggerScenarios":"Calling Search/SearchWithResult on a PanzunPlugin instance constructed without initializing p.scraper — e.g. a zero-value PanzunPlugin{} created by hand instead of via the plugin's constructor, or scraper initialization skipped/failing silently before registration.","commonSituations":"Plugin registered but its constructor bypassed (manual instantiation, reflection-based loading, config-driven creation that doesn't call init code); refactor moved scraper creation out of the constructor; tests instantiating the struct directly.","solutions":["Instantiate the plugin only through its constructor so p.scraper is set before search","Add a lazy-init or nil check that creates the scraper on first use if it is nil","Verify the scraper construction code isn't gated behind a config/env condition that is false in this environment"],"exampleFix":"// before\np := &panzun.PanzunPlugin{}\nresults, err := p.Search(keyword, nil) // error: cloudscraper not initialized\n// after\np := panzun.NewPanzunPlugin()\nresults, err := p.Search(keyword, nil)","handlingStrategy":"validation","validationCode":"if p == nil || p.scraper == nil {\n    return fmt.Errorf(\"plugin not initialized: scraper is nil\")\n}\n_ = p.Search(keyword, ext)","typeGuard":"func (p *PanzunPlugin) ready() bool { return p != nil && p.scraper != nil }","tryCatchPattern":"results, err := plugin.Search(keyword, ext)\nif err != nil {\n    if strings.Contains(err.Error(), \"cloudscraper not initialized\") {\n        plugin = panzun.NewPanzunPlugin() // rebuild and retry once\n        results, err = plugin.Search(keyword, ext)\n    }\n}","preventionTips":["Always construct plugins via their constructor, never struct literals","Add an assert-ready check in plugin registration","Cover constructor initialization with a unit test"],"tags":["go","plugin","initialization","nil-pointer","cloudscraper"],"backgroundTag":"module-init-failed","analyzedSha":"beaa56133755a548ebc51b090b3816e2ae044aa6","analyzedAt":"2026-09-07T00:31:18.025Z","contentChangedAt":"2026-09-07T00:31:18.025Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}