RayWangQvQ/BiliBiliToolPro · error · BiliValidationException
Cookie字符串为空
Error message
Cookie字符串为空
What it means
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.
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.
Example fix
// before (appsettings.json) "BiliBiliCookies": ["" ] // after "BiliBiliCookies": ["SESSDATA=xxx; bili_jct=yyy; buvid3=zzz; DedeUserID=123"]
Defensive patterns
Strategy: validation
Validate before calling
public static bool IsCookieUsable(string? cookieStr) =>
!string.IsNullOrWhiteSpace(cookieStr) &&
cookieStr.Contains('=') &&
cookieStr.Contains("SESSDATA", StringComparison.OrdinalIgnoreCase); Try / catch
try { cookieInfo.Check(); }
catch (BiliValidationException ex)
{
logger.LogError("Cookie配置无效: {Msg}", ex.Message);
return; // abort run early
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.
Related errors
AI-assisted analysis of RayWangQvQ/BiliBiliToolPro@c599b2c0da (2026-09-12).
Data as JSON: /api/errors/8d8405b0fbfc85a1.
Report an issue: GitHub.
Appendix: source
Thrown at src/Ray.BiliBiliTool.Infrastructure/Cookie/CookieInfo.cs:20
namespace Ray.BiliBiliTool.Infrastructure.Cookie;
public class CookieInfo(Dictionary<string, string> cookieDic)
{
public Dictionary<string, string> CookieItemDictionary { get; private set; } = cookieDic;
public string CookieStr =>
string.Join(
"; ",
CookieItemDictionary
.Select(item => $"{CkNameBuild(item.Key)}={CkValueBuild(item.Value)}")
.ToList()
);
public virtual void Check()
{
if (CookieItemDictionary == null || CookieItemDictionary.Count == 0)
throw new BiliValidationException("Cookie字符串为空");
}
protected virtual string CkNameBuild(string name)
{
return name;
}
protected virtual string CkValueBuild(string value)
{
return value;
}
public override string ToString()
{
var list = CookieItemDictionary.Select(d =>
$"{CkNameBuild(d.Key)}={CkValueBuild(d.Value)}"
);
return string.Join("; ", list);View on GitHub (pinned to c599b2c0da)