babalae/better-genshin-impact · error · FileNotFoundException

main js is empty.

Error message

main js is empty.

What it means

Thrown by ScriptProject.LoadCode when the main JS file (specified by Manifest.Main) exists but contains empty or null content. Despite the exception type being FileNotFoundException, the file exists — it's just empty. This is a content validation check after reading the file.

Source

Thrown at BetterGenshinImpact/Core/Script/Project/ScriptProject.cs:167

            try
            {
                engine.Interrupt();
            }
            catch (Exception e)
            {
                TaskControl.Logger.LogError(e, "中断脚本执行异常:" + e.Message);
            }

            engine.Dispose();
        }
    }

    public async Task<string> LoadCode()
    {
        var code = await File.ReadAllTextAsync(Path.Combine(ProjectPath, Manifest.Main));
        if (string.IsNullOrEmpty(code))
        {
            throw new FileNotFoundException("main js is empty.");
        }

        return code;
    }
}

View on GitHub (pinned to a7cb36712d)

Solutions

  1. Open the main JS file and verify it contains executable JavaScript code.
  2. If the file is empty, add the script logic or restore from a backup/version control.
  3. Check file size: if 0 bytes, re-download or recreate the script.
  4. Use a script template to ensure the main file has valid content.
Defensive patterns

Strategy: validation

Validate before calling

var code = await File.ReadAllTextAsync(Path.Combine(projectPath, manifest.Main));
if (string.IsNullOrWhiteSpace(code))
    throw new InvalidOperationException($"Main JS file is empty: {manifest.Main}");

Try / catch

try
{
    var code = await project.LoadCode();
}
catch (FileNotFoundException ex) when (ex.Message.Contains("main js is empty"))
{
    TaskControl.Logger.LogError("Main JS file has no content");
}

Prevention

When it happens

Trigger: Calling LoadCode() on a ScriptProject where Path.Combine(ProjectPath, Manifest.Main) exists but File.ReadAllTextAsync returns an empty string. The main JS entry-point file has zero bytes or only whitespace that gets read as empty.

Common situations: The main.js file was created but never filled with code. A file sync or extraction issue resulted in a zero-byte file. The script author created a placeholder file. A Git operation (merge, rebase) left the file empty.

Related errors


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