{"record":{"id":"da034968b49a30bb","repo":"babalae/better-genshin-impact","slug":"ocr","errorCode":null,"errorMessage":"不支持的 OCR 引擎类型","messagePattern":"不支持的 OCR 引擎类型","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"BetterGenshinImpact/Core/Recognition/OCR/OcrFactory.cs","lineNumber":43,"sourceCode":"    /// <summary>\n    ///  OCR 工厂,不可以直接实例化,请使用 App.ServiceProvider获取实例\n    /// </summary>\n    /// <param name=\"logger\"></param>\n    public OcrFactory(ILogger<BgiOnnxFactory> logger)\n    {\n        _logger = logger;\n        _config = GetConfig();\n    }\n\n    /// <summary>\n    /// 创建\n    /// </summary>\n    private IOcrService Create(OcrEngineTypes type)\n    {\n        var result = type switch\n        {\n            OcrEngineTypes.Paddle => CreatePaddleOcrInstance(),\n            _ => throw new ArgumentOutOfRangeException(Enum.GetName(type), type, \"不支持的 OCR 引擎类型\")\n        };\n        _logger.LogDebug(\"创建了类型为 {Type} 的 OCR服务\", Enum.GetName(type));\n        return result;\n    }\n\n    /// <summary>\n    /// 获取 OCR 配置\n    /// 为了单元测试\n    /// </summary>\n    /// <returns></returns>\n    private OtherConfig.Ocr GetConfig()\n    {\n        try\n        {\n            // 直接使用配置\n            return TaskContext.Instance().Config.OtherConfig.OcrConfig;\n        }\n        catch (Exception e)","sourceCodeStart":25,"sourceCodeEnd":61,"githubUrl":"https://github.com/babalae/better-genshin-impact/blob/a7cb36712dcb409be610257d877fcea3597e9d6b/BetterGenshinImpact/Core/Recognition/OCR/OcrFactory.cs#L25-L61","documentation":"OcrFactory.Create switches on OcrEngineTypes; currently only Paddle is implemented, and the default arm throws ArgumentOutOfRangeException with the offending enum name as the param name. This guards against an unknown/unset engine type reaching the factory.","triggerScenarios":"Casting an integer to OcrEngineTypes that isn't Paddle; a config value set to an engine type not yet supported; default(OcrEngineTypes) when the enum's 0 member is not a valid engine.","commonSituations":"Future enum members added without a factory case; config file referencing a removed/renamed engine; serialized state from an older version.","solutions":["Set the OCR engine config to the supported value (Paddle).","Validate the configured OcrEngineTypes at startup and reset to Paddle if invalid.","When adding an engine type, implement its case here in the same commit."],"exampleFix":"// before\nvar ocr = factory.Create(config.Engine); // unknown engine\n\n// after\nvar engine = Enum.IsDefined(config.Engine) ? config.Engine : OcrEngineTypes.Paddle;\nvar ocr = factory.Create(engine);","handlingStrategy":"validation","validationCode":"var engine = Enum.IsDefined(config.Engine) && config.Engine == OcrEngineTypes.Paddle\n    ? config.Engine\n    : OcrEngineTypes.Paddle;\nvar ocr = factory.Create(engine);","typeGuard":"static bool IsSupportedEngine(OcrEngineTypes e) => e == OcrEngineTypes.Paddle;","tryCatchPattern":null,"preventionTips":["Default OCR engine config to Paddle.","Validate the enum at config load.","Add a case whenever a new engine type is implemented."],"tags":["ocr","factory","enum","argument-validation","config"],"backgroundTag":null,"analyzedSha":"a7cb36712dcb409be610257d877fcea3597e9d6b","analyzedAt":"2026-08-13T16:44:57.548Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}