{"record":{"id":"0ff26d8787a586a3","repo":"babalae/better-genshin-impact","slug":"json","errorCode":null,"errorMessage":"解析配置组JSON配置失败","messagePattern":"解析配置组JSON配置失败","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"BetterGenshinImpact/Core/Script/Group/ScriptGroup.cs","lineNumber":51,"sourceCode":"\n    public ScriptGroup()\n    {\n        Projects.CollectionChanged += ProjectsCollectionChanged;\n    }\n\n    private void ProjectsCollectionChanged(object? sender, NotifyCollectionChangedEventArgs e)\n    {\n        OnPropertyChanged(nameof(Projects));\n    }\n\n    public string ToJson()\n    {\n        return JsonSerializer.Serialize(this, ConfigService.JsonOptions);\n    }\n\n    public static ScriptGroup FromJson(string json)\n    {\n        var group = JsonConvert.DeserializeObject<ScriptGroup>(json) ?? throw new Exception(\"解析配置组JSON配置失败\");\n        ResetGroupInfo(group);\n        return group;\n    }\n\n    public static void ResetGroupInfo(ScriptGroup group)\n    {\n        foreach (var project in group.Projects)\n        {\n            project.GroupInfo = group;\n        }\n    }\n\n    public void AddProject(ScriptGroupProject project)\n    {\n        project.GroupInfo = this;\n        Projects.Add(project);\n    }\n}","sourceCodeStart":33,"sourceCodeEnd":69,"githubUrl":"https://github.com/babalae/better-genshin-impact/blob/a7cb36712dcb409be610257d877fcea3597e9d6b/BetterGenshinImpact/Core/Script/Group/ScriptGroup.cs#L33-L69","documentation":"Thrown by ScriptGroup.FromJson when Newtonsoft.Json JsonConvert.DeserializeObject<ScriptGroup> returns null, indicating the input JSON could not be deserialized into a ScriptGroup object. Note this uses Newtonsoft.Json while ToJson uses System.Text.Json — a mixed-serializer pattern that can cause subtle serialization mismatches.","triggerScenarios":"Calling ScriptGroup.FromJson(json) with malformed JSON, empty string, JSON representing a different type, or JSON whose structure doesn't match ScriptGroup's expected properties. The null-coalescing throw only fires when deserialization yields null (not when it throws a JsonException — that propagates separately).","commonSituations":"Corrupted or manually-edited configuration group file. Version mismatch where the config file format changed but old files weren't migrated. Empty file content passed to FromJson.","solutions":["Validate the JSON is well-formed using a JSON linter before calling FromJson.","Ensure the JSON root is an object with ScriptGroup's expected properties (Index, Name, Config, Projects).","If the JSON is valid but yields null, check for serializer-specific issues (e.g. [JsonObject] attributes, missing parameterless constructor).","Wrap FromJson in try-catch to also handle JsonReaderException from malformed JSON."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"if (string.IsNullOrWhiteSpace(json))\n    throw new ArgumentException(\"JSON content is empty\");\n// Quick syntax check\nJsonConvert.DeserializeObject(json); // throws on malformed JSON","typeGuard":null,"tryCatchPattern":"try\n{\n    var group = ScriptGroup.FromJson(json);\n}\ncatch (Exception ex) when (ex.Message.Contains(\"解析配置组JSON配置失败\"))\n{\n    TaskControl.Logger.LogError(ex, \"Failed to parse script group config\");\n    // Offer to reset or restore default config\n}\ncatch (Newtonsoft.Json.JsonException ex)\n{\n    TaskControl.Logger.LogError(ex, \"Malformed JSON in script group config\");\n}","preventionTips":["Validate JSON syntax with a linter before deserialization.","Back up script group config files before modifying.","Ensure the JSON structure matches ScriptGroup's property names exactly."],"tags":["json","configuration","deserialization","script-group"],"backgroundTag":null,"analyzedSha":"a7cb36712dcb409be610257d877fcea3597e9d6b","analyzedAt":"2026-08-13T16:44:57.548Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}