{"record":{"id":"8d8405b0fbfc85a1","repo":"RayWangQvQ/BiliBiliToolPro","slug":"cookie-cookieinfo","errorCode":null,"errorMessage":"Cookie字符串为空","messagePattern":"Cookie字符串为空","errorType":"validation","errorClass":"BiliValidationException","httpStatus":null,"severity":"error","filePath":"src/Ray.BiliBiliTool.Infrastructure/Cookie/CookieInfo.cs","lineNumber":20,"sourceCode":"\nnamespace Ray.BiliBiliTool.Infrastructure.Cookie;\n\npublic class CookieInfo(Dictionary<string, string> cookieDic)\n{\n    public Dictionary<string, string> CookieItemDictionary { get; private set; } = cookieDic;\n\n    public string CookieStr =>\n        string.Join(\n            \"; \",\n            CookieItemDictionary\n                .Select(item => $\"{CkNameBuild(item.Key)}={CkValueBuild(item.Value)}\")\n                .ToList()\n        );\n\n    public virtual void Check()\n    {\n        if (CookieItemDictionary == null || CookieItemDictionary.Count == 0)\n            throw new BiliValidationException(\"Cookie字符串为空\");\n    }\n\n    protected virtual string CkNameBuild(string name)\n    {\n        return name;\n    }\n\n    protected virtual string CkValueBuild(string value)\n    {\n        return value;\n    }\n\n    public override string ToString()\n    {\n        var list = CookieItemDictionary.Select(d =>\n            $\"{CkNameBuild(d.Key)}={CkValueBuild(d.Value)}\"\n        );\n        return string.Join(\"; \", list);","sourceCodeStart":2,"sourceCodeEnd":38,"githubUrl":"https://github.com/RayWangQvQ/BiliBiliToolPro/blob/c599b2c0da964e16ea8c454397aa07bb16212628/src/Ray.BiliBiliTool.Infrastructure/Cookie/CookieInfo.cs#L2-L38","documentation":"CookieInfo.Check validates that the parsed cookie string produced at least one cookie item; if CookieItemDictionary is null or empty it throws BiliValidationException with 'Cookie字符串为空' (Cookie string is empty). This is a configuration validation guard: the tool cannot authenticate to Bilibili without cookie content.","triggerScenarios":"Configuring BiliBiliCookies with an empty string, whitespace, or a value lacking '=' separated key/value pairs so parsing yields zero items; passing a null cookie into CookieInfo construction.","commonSituations":"Fresh install where the cookie env var or config field was left blank; cookie copied incorrectly (e.g. only headers pasted without the Cookie line); secrets injection failing in Docker/K8s so the env var resolves to empty.","solutions":["Set BiliBiliCookies (config or env) to a real cookie string copied from a logged-in browser session (contains SESSDATA, bili_jct, buvid3).","Ensure the cookie string uses 'key=value; key2=value2' format with at least one '=' pair.","Verify secret injection in your container/orchestrator isn't producing an empty env var.","Call Check() right after constructing CookieInfo (or at startup) to fail fast with a clear message."],"exampleFix":"// before (appsettings.json)\n\"BiliBiliCookies\": [\"\" ]\n// after\n\"BiliBiliCookies\": [\"SESSDATA=xxx; bili_jct=yyy; buvid3=zzz; DedeUserID=123\"]","handlingStrategy":"validation","validationCode":"public static bool IsCookieUsable(string? cookieStr) =>\n    !string.IsNullOrWhiteSpace(cookieStr) &&\n    cookieStr.Contains('=') &&\n    cookieStr.Contains(\"SESSDATA\", StringComparison.OrdinalIgnoreCase);","typeGuard":null,"tryCatchPattern":"try { cookieInfo.Check(); }\ncatch (BiliValidationException ex)\n{\n    logger.LogError(\"Cookie配置无效: {Msg}\", ex.Message);\n    return; // abort run early\n}","preventionTips":["Verify BiliBiliCookies in appsettings/env is a full 'k=v; k2=v2' string","Confirm secret injection in Docker/K8s isn't producing empty values","Call Check() at startup to fail fast","Copy the Cookie request header, not other headers"],"tags":["cookie","config-validation","empty-value","startup"],"backgroundTag":"empty-required-field","analyzedSha":"c599b2c0da964e16ea8c454397aa07bb16212628","analyzedAt":"2026-09-12T09:48:04.090Z","contentChangedAt":"2026-09-12T09:48:04.090Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}