{"record":{"id":"befb20be3d477cb9","repo":"babalae/better-genshin-impact","slug":"js","errorCode":null,"errorMessage":"JS脚本未初始化","messagePattern":"JS脚本未初始化","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"BetterGenshinImpact/Core/Script/Group/ScriptGroupProject.cs","lineNumber":215,"sourceCode":"        //执行记录\n        ExecutionRecord executionRecord = new ExecutionRecord()\n        {\n            ServerStartTime =\n                GroupInfo?.Config.PathingConfig.TaskCompletionSkipRuleConfig.IsBoundaryTimeBasedOnServerTime ?? false\n                    ? ServerTimeHelper.GetServerTimeNow()\n                    : DateTimeOffset.Now,\n            StartTime = DateTime.Now,\n            GroupName = GroupInfo?.Name ?? \"\",\n            FolderName = FolderName,\n            ProjectName = Name,\n            Type = Type\n        };\n        ExecutionRecordStorage.SaveExecutionRecord(executionRecord);\n        if (Type == \"Javascript\")\n        {\n            if (Project == null)\n            {\n                throw new Exception(\"JS脚本未初始化\");\n            }\n            JsScriptSettingsObject ??= new ExpandoObject();\n\n            // 清理配置中的无效值\n            CleanInvalidSettingsValues();\n\n            var pathingPartyConfig = GroupInfo?.Config.PathingConfig;\n            await Project.ExecuteAsync(JsScriptSettingsObject, pathingPartyConfig);\n        }\n        else if (Type == \"KeyMouse\")\n        {\n            // 加载并执行\n            var json = await File.ReadAllTextAsync(Global.Absolute(@$\"User\\KeyMouseScript\\{Name}\"));\n            await KeyMouseMacroPlayer.PlayMacro(json, CancellationContext.Instance.Cts.Token, false);\n        }\n        else if (Type == \"Pathing\")\n        {\n            // 加载并执行","sourceCodeStart":197,"sourceCodeEnd":233,"githubUrl":"https://github.com/babalae/better-genshin-impact/blob/a7cb36712dcb409be610257d877fcea3597e9d6b/BetterGenshinImpact/Core/Script/Group/ScriptGroupProject.cs#L197-L233","documentation":"Thrown during ScriptGroupProject.Run() when the project Type is \"Javascript\" but the Project property (a ScriptProject instance) is null. Project is normally set by BuildScriptProjectRelation, which must be called before Run. This guard ensures the JS engine and manifest are loaded before execution.","triggerScenarios":"Calling Run() on a ScriptGroupProject of Type \"Javascript\" where BuildScriptProjectRelation() was never called or failed silently. This can happen if the project was deserialized from JSON without going through the initialization path that sets Project.","commonSituations":"Loading a ScriptGroup from JSON and directly calling Run() on its projects without first calling BuildScriptProjectRelation. A deserialization or migration path that skips project relation building.","solutions":["Call BuildScriptProjectRelation() on the project before invoking Run().","Ensure the ScriptGroup initialization pipeline (FromJson → ResetGroupInfo → BuildScriptProjectRelation) is fully executed.","Add a null-check guard: if (Project == null) BuildScriptProjectRelation(); before Run()."],"exampleFix":"// before\nawait project.Run();\n// after\nproject.BuildScriptProjectRelation();\nawait project.Run();","handlingStrategy":"validation","validationCode":"if (project.Type == \"Javascript\" && project.Project == null)\n{\n    project.BuildScriptProjectRelation();\n}\nawait project.Run();","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always call BuildScriptProjectRelation() before Run() for Javascript projects.","Integrate project initialization into the ScriptGroup loading pipeline.","Add a pre-flight check before executing a group: verify all JS projects have non-null Project."],"tags":["script-execution","initialization","script-group","state-validation"],"backgroundTag":null,"analyzedSha":"a7cb36712dcb409be610257d877fcea3597e9d6b","analyzedAt":"2026-08-13T16:44:57.548Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}