RayWangQvQ/BiliBiliToolPro · error · ArgumentOutOfRangeException

Invalid taskCode

Error message

Invalid taskCode: {taskCode}

What it means

CompleteViewAsync maps a VIP viewing task code (taskCode) to a channel via a switch expression; any taskCode other than 'animatetab' or 'filmtab' throws ArgumentOutOfRangeException with 'Invalid taskCode: {taskCode}'. This is a local guard against calling the view-completion flow with an unsupported task identifier.

Solutions

  1. Only pass 'animatetab' or 'filmtab' to CompleteViewAsync; route other task codes to CompleteV2Async instead.
  2. Add the new tab code to the switch mapping if Bilibili introduced one (e.g. "newtab" => "new_channel").
  3. Log the full task list from GetCombineAsync and pick codes the service explicitly supports.
  4. Validate taskCode before calling to avoid an unhandled exception in the daily run.

Example fix

// before
await service.CompleteViewAsync("viewcomplete", ck);
// after
if (taskCode is "animatetab" or "filmtab")
    await service.CompleteViewAsync(taskCode, ck);
else
    await service.CompleteV2Async(taskCode, ck);
Defensive patterns

Strategy: validation

Validate before calling

private static readonly HashSet<string> SupportedViewTaskCodes = new() { "animatetab", "filmtab" };
if (!SupportedViewTaskCodes.Contains(taskCode))
{
    logger.LogWarning("跳过不支持的任务Code: {TaskCode}", taskCode);
    return false;
}

Try / catch

try { await svc.CompleteViewAsync(taskCode, ck); }
catch (ArgumentOutOfRangeException)
{
    logger.LogWarning("任务Code {TaskCode} 不支持浏览完成,改用CompleteV2Async", taskCode);
    await svc.CompleteV2Async(taskCode, ck);
}

Prevention

When it happens

Trigger: Calling CompleteViewAsync directly with a taskCode string obtained from a different task list (e.g. 'viewcomplete' or a numeric code) that isn't one of the two supported viewing tabs, or after Bilibili introduces a new tab code the mapping doesn't handle.

Common situations: Custom task automation passing codes from GetCombineAsync's task list; Bilibili renaming/adding tab codes upstream; typo in the taskCode string when wiring up tasks manually.

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


AI-assisted analysis of RayWangQvQ/BiliBiliToolPro@c599b2c0da (2026-09-12). Data as JSON: /api/errors/92c33dac4ea12900. Report an issue: GitHub.

Appendix: source

Thrown at src/Ray.BiliBiliTool.DomainService/VipBigPointDomainService.cs:216

        var request = new ReceiveOrCompleteTaskRequest(taskCode);
        var re = await apiApi.VipBigPointCompleteAsync(request, ck.ToString());
        if (re.Code == 0)
        {
            logger.LogInformation("已完成");
            return true;
        }

        logger.LogInformation("失败:{msg}", re.ToJsonStr());
        return false;
    }

    public async Task<bool> CompleteViewAsync(string taskCode, BiliCookie ck)
    {
        var channel = taskCode switch
        {
            "animatetab" => "jp_channel",
            "filmtab" => "tv_channel",
            _ => throw new ArgumentOutOfRangeException(
                nameof(taskCode),
                $"Invalid taskCode: {taskCode}"
            ),
        };

        logger.LogInformation("开始浏览");
        await Task.Delay(10 * 1000);

        var request = new ViewRequest(channel);
        var re = await apiApi.VipBigPointViewComplete(request, ck.ToString());
        if (re.Code == 0)
        {
            logger.LogInformation("浏览完成");
            return true;
        }

        logger.LogInformation("浏览失败:{msg}", re.ToJsonStr());
        return false;

View on GitHub (pinned to c599b2c0da)