RayWangQvQ/BiliBiliToolPro · error · BiliBusinessException
投币发生未预计异常:
Error message
投币发生未预计异常:{result.Message} What it means
Thrown by DoAddCoinForVideo when the Bilibili coin API returns a non-zero code that is NOT in the known 'expected failure' list (donateContinueStatusDic, e.g. insufficient coins, already coined). The library treats known codes as benign (logs and returns false) but treats unknown codes as unexpected business errors and aborts the coin-donation task by throwing BiliBusinessException with the API's own message.
Solutions
- Log result.Code and result.Message to identify the exact Bilibili error code returned.
- If the code is a known benign condition (e.g. coins exhausted), add it to the donateContinueStatusDic configuration so the task skips instead of throwing.
- Check for a newer version of Ray.BiliBiliTool that recognizes the new error code.
- If triggered by risk control, pause the automation, reduce coin count, or refresh the account cookie.
Example fix
// before: unknown code -> throw
if (!_donateContinueStatusDic.Any(x => x.Key == result.Code.ToString()))
throw new BiliBusinessException($"投币发生未预计异常:{result.Message}");
// after: log and skip for new benign codes
if (result.Code == -352) // risk control
{
logger.LogWarning("投币被风控拦截,跳过:{msg}", result.Message);
return false;
}
throw new BiliBusinessException($"投币发生未预计异常:{result.Message}"); Defensive patterns
Strategy: try-catch
Validate before calling
var knownCodes = new HashSet<int> { 0, -101, -104, 110010 }; // plus configured continue codes
// no pre-check possible for unknown codes; catch at call site instead Try / catch
try
{
await donateCoinDomainService.DoAddCoinForVideo(video, selectLike, ck);
}
catch (BiliBusinessException ex)
{
logger.LogWarning("投币跳过:{msg}", ex.Message);
// continue with remaining daily tasks instead of crashing the run
} Prevention
- Keep the donateContinueStatusDic updated with benign Bilibili coin error codes.
- Run with an up-to-date library version so newly mapped error codes are recognized.
- Wrap per-video coin donation so one failure doesn't abort the whole daily run.
When it happens
Trigger: apiApi.AddCoinForVideo returns result.Code != 0 and result.Code is not a key in _donateContinueStatusDic — e.g. Bilibili changes/adds an error code, risk-control blocks the account, or the coin endpoint returns a new rate-limit or security-verification code.
Common situations: Bilibili API behavior changes after a site update; account flagged by risk control returning unusual codes; new Bilibili error code for coin exhaustion that the local dictionary doesn't recognize yet.
Related errors
AI-assisted analysis of RayWangQvQ/BiliBiliToolPro@c599b2c0da (2026-09-12).
Data as JSON: /api/errors/183abc64f705ae91.
Report an issue: GitHub.
Appendix: source
Thrown at src/Ray.BiliBiliTool.DomainService/DonateCoinDomainService.cs:194
}
if (result.Code == 0)
{
_expDic.TryGetValue("每日投币", out int exp);
logger.LogInformation("投币成功,经验+{exp} √", exp);
return true;
}
if (_donateContinueStatusDic.Any(x => x.Key == result.Code.ToString()))
{
logger.LogError("投币失败,原因:{msg}", result.Message);
return false;
}
else
{
string errorMsg = $"投币发生未预计异常:{result.Message}";
logger.LogError(errorMsg);
throw new BiliBusinessException(errorMsg);
}
}
#region private
/// <summary>
/// 获取今日的目标投币数
/// </summary>
/// <returns></returns>
private async Task<int> GetNeedDonateCoinNum(BiliCookie ck)
{
//获取自定义配置投币数
int configCoins = _dailyTaskOptions.NumberOfCoins;
if (configCoins <= 0)
{
logger.LogInformation("已配置为跳过投币任务");
return configCoins;View on GitHub (pinned to c599b2c0da)