{"record":{"id":"1b60e874cb05030c","repo":"BigPizzaV3/CodexPlusPlus","slug":"error-1b60e8","errorCode":null,"errorMessage":"倍率接口返回了无效倍率","messagePattern":"倍率接口返回了无效倍率","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/codex-plus-core/src/sub2api.rs","lineNumber":116,"sourceCode":"        return format!(\"{cleaned}/sub2api/billing\");\n    }\n    format!(\"{cleaned}/v1/sub2api/billing\")\n}\n\nfn validate_sub2api_billing_response(response: &Sub2ApiBillingResponse) -> anyhow::Result<()> {\n    if response.object != \"sub2api.key_billing\"\n        || response.schema_version != 1\n        || response.billing_scope != \"token\"\n    {\n        anyhow::bail!(\"倍率接口返回结构不是 sub2api.key_billing\");\n    }\n    for value in [\n        response.group_rate_multiplier,\n        response.resolved_rate_multiplier,\n        response.effective_rate_multiplier,\n    ] {\n        if !value.is_finite() || value < 0.0 {\n            anyhow::bail!(\"倍率接口返回了无效倍率\");\n        }\n    }\n    if let Some(value) = response.user_rate_multiplier {\n        if !value.is_finite() || value < 0.0 {\n            anyhow::bail!(\"倍率接口返回了无效用户倍率\");\n        }\n    }\n    if response.observed_at.trim().is_empty() {\n        anyhow::bail!(\"倍率接口缺少观测时间\");\n    }\n    Ok(())\n}\n\nfn sub2api_error_message(body: &str) -> Option<String> {\n    let payload: Value = serde_json::from_str(body).ok()?;\n    for path in [&[\"error\", \"message\"][..], &[\"message\"][..], &[\"error\"][..]] {\n        let mut current = &payload;\n        for key in path {","sourceCodeStart":98,"sourceCodeEnd":134,"githubUrl":"https://github.com/BigPizzaV3/CodexPlusPlus/blob/b1ed92e5e4a2d74095d4b8db5af43cef7acba9c6/crates/codex-plus-core/src/sub2api.rs#L98-L134","documentation":"The validator loops over group_rate_multiplier, resolved_rate_multiplier, and effective_rate_multiplier and bails if any is non-finite (NaN/inf) or negative. This protects downstream cost math from garbage multiplier values that would produce nonsense billing estimates.","triggerScenarios":"上游返回的任一必填倍率为 NaN、正负无穷或负数（JSON 解析为 f64 后 is_finite() 为假或 < 0.0）。","commonSituations":"上游数据库倍率字段损坏或未初始化；上游 bug 序列化了 null/Infinity；配置了负数折扣倍率的上游。","solutions":["在 sub2api 管理后台检查并修正分组/密钥的倍率配置为非负有限值","直接请求倍率端点查看原始 JSON，确认是上游数据问题","升级上游 sub2api 版本修复序列化 bug"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"fn multipliers_sane(body: &serde_json::Value) -> bool {\n    [\"group_rate_multiplier\", \"resolved_rate_multiplier\", \"effective_rate_multiplier\"]\n        .iter()\n        .all(|k| body[k].as_f64().map(|v| v.is_finite() && v >= 0.0).unwrap_or(false))\n}","typeGuard":null,"tryCatchPattern":"match fetch_sub2api_billing_info(&profile).await {\n    Err(e) if e.to_string().contains(\"无效倍率\") => {\n        eprintln!(\"上游倍率数据异常：{e}，请到 sub2api 后台检查倍率配置\");\n    }\n    other => other?,\n}","preventionTips":["在 sub2api 后台定期核对分组/密钥倍率为非负有限值","上游异常时先用 curl 查看原始 JSON 排除传输层问题","升级 sub2api 修复倍率字段的序列化 bug"],"tags":["validation","numeric","sub2api","billing"],"backgroundTag":"invalid-argument-value","analyzedSha":"b1ed92e5e4a2d74095d4b8db5af43cef7acba9c6","analyzedAt":"2026-09-19T23:35:21.129Z","contentChangedAt":"2026-09-19T23:35:21.129Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}