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

  1. Call BuildScriptProjectRelation() on the project before invoking Run().
  2. Ensure the ScriptGroup initialization pipeline (FromJson → ResetGroupInfo → BuildScriptProjectRelation) is fully executed.
  3. 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

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


AI-assisted analysis of babalae/better-genshin-impact@a7cb36712d (2026-08-13). Data as JSON: /api/errors/befb20be3d477cb9. Report an issue: GitHub.