babalae/better-genshin-impact · error · Exception
JS脚本未初始化
Error message
JS脚本未初始化
What it means
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.
Source
Thrown at BetterGenshinImpact/Core/Script/Group/ScriptGroupProject.cs:215
//执行记录
ExecutionRecord executionRecord = new ExecutionRecord()
{
ServerStartTime =
GroupInfo?.Config.PathingConfig.TaskCompletionSkipRuleConfig.IsBoundaryTimeBasedOnServerTime ?? false
? ServerTimeHelper.GetServerTimeNow()
: DateTimeOffset.Now,
StartTime = DateTime.Now,
GroupName = GroupInfo?.Name ?? "",
FolderName = FolderName,
ProjectName = Name,
Type = Type
};
ExecutionRecordStorage.SaveExecutionRecord(executionRecord);
if (Type == "Javascript")
{
if (Project == null)
{
throw new Exception("JS脚本未初始化");
}
JsScriptSettingsObject ??= new ExpandoObject();
// 清理配置中的无效值
CleanInvalidSettingsValues();
var pathingPartyConfig = GroupInfo?.Config.PathingConfig;
await Project.ExecuteAsync(JsScriptSettingsObject, pathingPartyConfig);
}
else if (Type == "KeyMouse")
{
// 加载并执行
var json = await File.ReadAllTextAsync(Global.Absolute(@$"User\KeyMouseScript\{Name}"));
await KeyMouseMacroPlayer.PlayMacro(json, CancellationContext.Instance.Cts.Token, false);
}
else if (Type == "Pathing")
{
// 加载并执行View on GitHub (pinned to a7cb36712d)
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().
Example fix
// before await project.Run(); // after project.BuildScriptProjectRelation(); await project.Run();
Defensive patterns
Strategy: validation
Validate before calling
if (project.Type == "Javascript" && project.Project == null)
{
project.BuildScriptProjectRelation();
}
await project.Run(); Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- 预热图片未找到: {modelType.PreHeatImagePath}
- 解析配置组JSON配置失败
- FolderName 为空
- 路径追踪任务未完全走完,判定失败,触发异常!
- 实际战斗次数({pathingTask.SuccessFight})<预期战斗次数({fightCount}),判定失败
AI-assisted analysis of babalae/better-genshin-impact@a7cb36712d (2026-08-13).
Data as JSON: /api/errors/befb20be3d477cb9.
Report an issue: GitHub.