{"record":{"id":"a2215a6ac82b3deb","repo":"babalae/better-genshin-impact","slug":"config-json-a2215a","errorCode":null,"errorMessage":"config.json 解析失败","messagePattern":"config\\.json 解析失败","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"critical","filePath":"BetterGenshinImpact/GameTask/AutoLeyLineOutcrop/AutoLeyLineOutcropTask.cs","lineNumber":231,"sourceCode":"        else\n        {\n            _taskParam.Timeout = _taskParam.FightConfig.Timeout;\n        }\n    }\n\n    private void LoadConfigData()\n    {\n        // Load and validate the static ley line route config from disk.\n        var workDir = Global.Absolute(@\"GameTask\\AutoLeyLineOutcrop\");\n        var configPath = Path.Combine(workDir, \"Assets\", \"config.json\");\n        if (!File.Exists(configPath))\n        {\n            throw new FileNotFoundException(\"config.json 未找到\", configPath);\n        }\n\n        var json = File.ReadAllText(configPath);\n        _configData = JsonSerializer.Deserialize<AutoLeyLineConfigData>(json)\n                      ?? throw new Exception(\"config.json 解析失败\");\n    }\n\n    private void LoadRecognitionObjects()\n    {\n        // Template ROIs are tuned for the 1080p capture region.\n        _openRo = BuildTemplate(\"Assets/icon/open.png\");\n        _closeRo = BuildTemplate(\"Assets/icon/close.png\");\n        _paimonMenuRo = BuildTemplate(\"Assets/icon/paimon_menu.png\", new Rect(0, 0, ScaleTo1080(640), ScaleTo1080(216)));\n        _boxIconRo = BuildTemplate(\"Assets/icon/box.png\");\n        _mapSettingButtonRo = BuildTemplate(\"Assets/icon/map_setting_button.bmp\");\n        _handbookTrackActionRo = BuildTemplate(\"Assets/icon/handbook_track_action_left.png\", HandbookTrackActionButtonRoi, 0.72);\n\n        _ocrRo1 = RecognitionObject.Ocr(ScaleTo1080(800), ScaleTo1080(200), ScaleTo1080(300), ScaleTo1080(100));\n        _ocrRo2 = RecognitionObject.Ocr(ScaleTo1080(0), ScaleTo1080(200), ScaleTo1080(300), ScaleTo1080(300));\n        _ocrRo3 = RecognitionObject.Ocr(ScaleTo1080(1200), ScaleTo1080(520), ScaleTo1080(300), ScaleTo1080(300));\n    }\n\n    private static int ScaleTo1080(int value)","sourceCodeStart":213,"sourceCodeEnd":249,"githubUrl":"https://github.com/babalae/better-genshin-impact/blob/a7cb36712dcb409be610257d877fcea3597e9d6b/BetterGenshinImpact/GameTask/AutoLeyLineOutcrop/AutoLeyLineOutcropTask.cs#L213-L249","documentation":"Thrown by LoadConfigData when JsonSerializer.Deserialize<AutoLeyLineConfigData> returns null after reading config.json. System.Text.Json returns null when the JSON content is literally 'null' or when the root token cannot be deserialized into the target type structure. This indicates the file exists but its content is not valid AutoLeyLineConfigData JSON.","triggerScenarios":"LoadConfigData reads config.json, deserializes it, and checks for null. Fires when the file is empty, contains only 'null', has a JSON syntax error that produces a null result, or has a schema mismatch (e.g. missing required root-level properties that cause the deserializer to return a default/null object).","commonSituations":"The config.json was corrupted by a failed write or manual edit; the file is empty (zero bytes); the JSON schema changed in a version update but an old config.json was left behind; a text editor saved the file with invalid JSON (trailing commas, unescaped characters).","solutions":["Restore config.json from a known-good backup or reinstall the application to get the bundled version.","Open config.json in a JSON validator/linter to find and fix syntax errors.","Verify the file is not empty and contains the expected root object with LeyLinePositions, MapPositions, and ErrorThreshold properties.","If the schema changed after an update, replace the old file with the one from the new release."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Before deserializing, validate JSON is non-empty and non-null\nvar json = File.ReadAllText(configPath);\nif (string.IsNullOrWhiteSpace(json) || json.Trim() == \"null\")\n{\n    Logger.LogError(\"config.json 内容为空或 null\");\n    return;\n}","typeGuard":null,"tryCatchPattern":"try\n{\n    _configData = JsonSerializer.Deserialize<AutoLeyLineConfigData>(json)\n                 ?? throw new Exception(\"config.json 解析失败\");\n}\ncatch (JsonException ex)\n{\n    logger.LogError(ex, \"config.json 格式错误，请恢复默认配置\");\n    throw new Exception(\"config.json 格式错误，请重新安装或恢复默认配置\", ex);\n}","preventionTips":["Do not hand-edit bundled JSON config files without validating them.","Back up config.json before modifying so it can be restored.","Use a JSON linter to validate the file after editing.","Reinstall if the file is corrupted to get the bundled version."],"tags":["ley-line","json","deserialization","assets","corruption"],"backgroundTag":null,"analyzedSha":"a7cb36712dcb409be610257d877fcea3597e9d6b","analyzedAt":"2026-08-13T16:44:57.548Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}