babalae/better-genshin-impact · error · Exception

FolderName 为空

Error message

FolderName 为空

What it means

Thrown by ScriptGroupProject.BuildScriptProjectRelation when FolderName is null or empty. This method lazily constructs the ScriptProject from FolderName — it's a guard ensuring the folder reference exists before attempting to build the project relation. Called from GetHttpAllowedUrlsHash and other places that need the Project.

Solutions

  1. Check Type and FolderName before calling BuildScriptProjectRelation — only 'Javascript' projects have folders.
  2. Ensure the ScriptGroupProject was properly constructed with a valid FolderName for JS projects.
  3. Guard callers: if (project.Type == "Javascript" && !string.IsNullOrEmpty(project.FolderName)) before accessing Project.

Example fix

// before
project.BuildScriptProjectRelation();
// after
if (!string.IsNullOrEmpty(project.FolderName))
{
    project.BuildScriptProjectRelation();
}
Defensive patterns

Strategy: validation

Validate before calling

if (project.Type == "Javascript" && !string.IsNullOrEmpty(project.FolderName))
{
    project.BuildScriptProjectRelation();
}

Type guard

static bool CanBuildProjectRelation(ScriptGroupProject p) =>
    p.Type == "Javascript" && !string.IsNullOrEmpty(p.FolderName);

Prevention

When it happens

Trigger: Calling BuildScriptProjectRelation() or GetHttpAllowedUrlsHash() on a ScriptGroupProject that was created without a folder name (e.g. via BuildShellProject which passes empty string as folder). Any ScriptGroupProject instance whose FolderName was never set or was set to empty.

Common situations: A Shell-type project or KeyMouse-type project (which don't have script folders) triggers a code path that calls BuildScriptProjectRelation. Incorrectly configured ScriptGroupProject JSON where FolderName is missing. Accidental access to Project-related members on non-JS project types.

Related errors


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

Appendix: source

Thrown at BetterGenshinImpact/Core/Script/Group/ScriptGroupProject.cs:177

    public static ScriptGroupProject BuildShellProject(string command)
    {
        return new ScriptGroupProject(command, "", "Shell");
    }

    public static ScriptGroupProject BuildPathingProject(string name, string folder)
    {
        return new ScriptGroupProject(name, folder, "Pathing");
    }

    /// <summary>
    /// 通过 FolderName 查找 ScriptProject
    /// </summary>
    public void BuildScriptProjectRelation()
    {
        if (string.IsNullOrEmpty(FolderName))
        {
            throw new Exception("FolderName 为空");
        }
        Project = new ScriptProject(FolderName);
    }

    public string GetHttpAllowedUrlsHash()
    {
        if (Project == null)
        {
            BuildScriptProjectRelation();
        }
        if (Project == null)
        {
            return "";
        }
        return string.Join("|", Project.Manifest.HttpAllowedUrls);
    }

    public async Task Run()

View on GitHub (pinned to a7cb36712d)