{"record":{"id":"74e4f04929ef2b9a","repo":"fish2018/pansou","slug":"s-w-74e4f0","errorCode":null,"errorMessage":"[%s] 创建搜索会话请求失败: %w","messagePattern":"\\[(.+?)\\] 创建搜索会话请求失败: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"plugin/jupansou/jupansou.go","lineNumber":175,"sourceCode":"\t// exchanging encrypted URLs to avoid unnecessary transfer requests.\n\tkeywordLower := strings.ToLower(strings.TrimSpace(keyword))\n\tfilteredItems := items[:0]\n\tfor _, item := range items {\n\t\tif keywordLower == \"\" || strings.Contains(strings.ToLower(item.Title), keywordLower) {\n\t\t\tfilteredItems = append(filteredItems, item)\n\t\t}\n\t}\n\n\tresults := p.exchangeItems(client, filteredItems)\n\treturn plugin.FilterResultsByKeyword(results, keyword), nil\n}\n\nfunc (p *JuPansouPlugin) ensureSearchSession(client *http.Client) error {\n\tctx, cancel := context.WithTimeout(context.Background(), jupansouTimeout)\n\tdefer cancel()\n\treq, err := http.NewRequestWithContext(ctx, http.MethodGet, jupansouBaseURL+\"/api/search/session\", nil)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"[%s] 创建搜索会话请求失败: %w\", p.Name(), err)\n\t}\n\treq.Header.Set(\"User-Agent\", \"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 Chrome/124.0 Safari/537.36\")\n\treq.Header.Set(\"Accept\", \"application/json\")\n\treq.Header.Set(\"Referer\", jupansouBaseURL+\"/\")\n\treq.Header.Set(\"X-Requested-With\", \"XMLHttpRequest\")\n\tresp, err := client.Do(req)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"[%s] 搜索会话请求失败: %w\", p.Name(), err)\n\t}\n\tdefer resp.Body.Close()\n\tif resp.StatusCode != http.StatusOK {\n\t\treturn fmt.Errorf(\"[%s] 搜索会话返回状态码: %d\", p.Name(), resp.StatusCode)\n\t}\n\treturn nil\n}\n\nfunc (p *JuPansouPlugin) exchangeItems(client *http.Client, items []juPansouStreamItem) []model.SearchResult {\n\tresults := make([]model.SearchResult, 0, len(items))","sourceCodeStart":157,"sourceCodeEnd":193,"githubUrl":"https://github.com/fish2018/pansou/blob/beaa56133755a548ebc51b090b3816e2ae044aa6/plugin/jupansou/jupansou.go#L157-L193","documentation":"ensureSearchSession wraps errors from http.NewRequestWithContext when constructing the GET request to the /api/search/session endpoint used to establish cookies/session state before searching. Construction errors indicate a malformed URL for the session endpoint.","triggerScenarios":"http.NewRequestWithContext fails building the GET to jupansouBaseURL+\"/api/search/session\" — i.e. jupansouBaseURL is empty, malformed, or contains invalid characters.","commonSituations":"Misconfigured or empty base URL constant; trailing whitespace/newline in the base URL; upstream moved the session endpoint so a hand-edited URL is invalid.","solutions":["Unwrap the error to see the URL parse failure detail.","Validate jupansouBaseURL parses cleanly: url.Parse(jupansouBaseURL) and check scheme/host.","Fix or update the base URL constant to match the current upstream.","Verify no environment-specific override injects a bad base URL."],"exampleFix":"// before: possibly malformed base\nbase := os.Getenv(\"JUPANSOU_BASE\")\n// after: validate before use\nu, err := url.Parse(base)\nif err != nil || u.Scheme == \"\" || u.Host == \"\" {\n    return fmt.Errorf(\"invalid JUPANSOU_BASE: %q\", base)\n}","handlingStrategy":"validation","validationCode":"u, err := url.Parse(jupansouBaseURL)\nif err != nil || u.Scheme == \"\" || u.Host == \"\" {\n    return fmt.Errorf(\"jupansouBaseURL invalid: %q\", jupansouBaseURL)\n}\nsessionURL := u.Scheme + \"://\" + u.Host + \"/api/search/session\"\nif _, err := url.Parse(sessionURL); err != nil { return err }","typeGuard":null,"tryCatchPattern":"if err := p.ensureSearchSession(client); err != nil && strings.Contains(err.Error(), \"创建搜索会话请求失败\") {\n    log.Printf(\"session request could not be constructed, check base URL: %v\", err)\n}","preventionTips":["Validate the base URL once at plugin init.","Trim whitespace from any environment-provided base URL.","Add a startup smoke test hitting the session endpoint."],"tags":["http","url","session","request-construction"],"backgroundTag":"invalid-url-format","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"}