{"record":{"id":"320911b8b3a1ce2c","repo":"fish2018/pansou","slug":"error-320911","errorCode":null,"errorMessage":"账号和密码不能为空","messagePattern":"账号和密码不能为空","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"plugin/panlian/panlian.go","lineNumber":1063,"sourceCode":"\t\t\ttime.Sleep(time.Duration(attempt+1) * 200 * time.Millisecond)\n\t\t\tcontinue\n\t\t}\n\t\tif err := json.Unmarshal(body, out); err != nil {\n\t\t\tif bytes.Contains(body, []byte(\"请先登录\")) || bytes.Contains(body, []byte(\"login\")) {\n\t\t\t\treturn fmt.Errorf(\"%w: %s\", errLoginRequired, string(body))\n\t\t\t}\n\t\t\treturn fmt.Errorf(\"解析接口响应失败: %w\", err)\n\t\t}\n\t\treturn nil\n\t}\n\n\treturn lastErr\n}\n\nfunc (p *PanlianPlugin) doLogin(username string, password string, remember bool) (string, *LoginResponse, error) {\n\tusername = strings.TrimSpace(username)\n\tif username == \"\" || password == \"\" {\n\t\treturn \"\", nil, fmt.Errorf(\"账号和密码不能为空\")\n\t}\n\tjar, _ := cookiejar.New(nil)\n\tclient := &http.Client{\n\t\tTimeout: RequestTimeout,\n\t\tJar:     jar,\n\t}\n\n\t// 站点登录只认预先由公开接口建立的 PHPSESSID。\n\tctx, cancel := context.WithTimeout(context.Background(), RequestTimeout)\n\treq, err := http.NewRequestWithContext(ctx, http.MethodGet, DefaultBaseURL+\"/api/get_types.php\", nil)\n\tif err != nil {\n\t\tcancel()\n\t\treturn \"\", nil, err\n\t}\n\tp.setPanlianHeaders(req, \"\", DefaultBaseURL+\"/all-videos.php\")\n\tresp, err := client.Do(req)\n\tif err != nil {\n\t\tcancel()","sourceCodeStart":1045,"sourceCodeEnd":1081,"githubUrl":"https://github.com/fish2018/pansou/blob/beaa56133755a548ebc51b090b3816e2ae044aa6/plugin/panlian/panlian.go#L1045-L1081","documentation":"doLogin validates inputs before attempting authentication and returns this error when username or password is empty after trimming whitespace. It is a synchronous pre-condition check, so no network call is made.","triggerScenarios":"Calling p.doLogin(\"\", \"\", ...) or with a whitespace-only username/password, e.g. when user config fields are blank or only contain spaces.","commonSituations":"Missing PANLIAN username/password in config file or env; credentials loaded from an empty database record; TrimSpace turning \"  \" into \"\".","solutions":["Provide non-empty username and password in the user configuration before calling doLogin","Validate credentials at startup/config-load time and fail fast with a clear message","Trim inputs on the caller side and check for emptiness before invoking login"],"exampleFix":"// before\n_, _, err := p.doLogin(cfg.Username, cfg.Password, true)\n// after\nif strings.TrimSpace(cfg.Username) == \"\" || strings.TrimSpace(cfg.Password) == \"\" {\n    return errors.New(\"panlian 账号或密码未配置\")\n}\n_, _, err := p.doLogin(cfg.Username, cfg.Password, true)","handlingStrategy":"validation","validationCode":"if strings.TrimSpace(cfg.PanlianUser) == \"\" || strings.TrimSpace(cfg.PanlianPass) == \"\" {\n    return errors.New(\"panlian 凭据未配置\")\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Validate credential fields at config load / startup","Never store whitespace-padded credentials; trim on ingest","Fail fast with a clear config error instead of reaching the login call"],"tags":["validation","authentication","config","go"],"backgroundTag":"empty-required-field","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"}