babalae/better-genshin-impact · error · Exception
从 library 字段读取路径 '{path}' 失败: {ex.Message}
Error message
从 library 字段读取路径 '{path}' 失败: {ex.Message} What it means
Thrown during ClearScript engine initialization when normalizing a library search path from the manifest's Library field fails. ScriptUtils.NormalizePath attempts to resolve a relative path against the working directory; if it throws (e.g. due to illegal characters, path format issues, or I/O errors), the error is wrapped with context about which library path caused it.
Source
Thrown at BetterGenshinImpact/Core/Script/EngineExtend.cs:126
engine.AddHostObject("htmlMask", new HtmlMask(workDir));
// 导入 JavaScript 模块
// https://microsoft.github.io/ClearScript/2023/01/24/module-interop.html
// https://github.com/microsoft/ClearScript/blob/master/ClearScriptTest/V8ModuleTest.cs
engine.DocumentSettings.AccessFlags = DocumentAccessFlags.AllowCategoryMismatch;
if (searchPaths != null)
{
var normalizedPaths = new List<string>();
foreach (var path in searchPaths)
{
try
{
var normalizedPath = ScriptUtils.NormalizePath(workDir, path);
normalizedPaths.Add(normalizedPath);
}
catch (Exception ex)
{
throw new Exception($"从 library 字段读取路径 '{path}' 失败: {ex.Message}", ex);
}
}
if (normalizedPaths.Count > 0)
{
engine.DocumentSettings.SearchPath = string.Join(';', normalizedPaths);
}
}
}
public static void AddAllGlobalMethod(IScriptEngine engine)
{
// // 获取GlobalMethod类的所有静态方法
// var methods = typeof(GlobalMethod).GetMethods(BindingFlags.Static | BindingFlags.Public);
//
// foreach (var method in methods)
// {
// // 使用方法名首字母小写作为HostObject的名称View on GitHub (pinned to a7cb36712d)
Solutions
- Inspect the manifest.json Library field for the specific path mentioned in the error message.
- Verify each library path uses valid OS path separators and contains no illegal characters.
- Test the path independently: Directory.Exists(Path.Combine(scriptRoot, libraryPath)).
- Ensure the referenced directories actually exist on disk.
Example fix
// manifest.json before "library": ["..\\bad<>path"] // after "library": ["../shared/libs"]
Defensive patterns
Strategy: validation
Validate before calling
foreach (var libPath in manifest.Library)
{
var full = Path.Combine(workDir, libPath);
if (!Directory.Exists(full))
throw new DirectoryNotFoundException($"Library path not found: {full}");
// Check for illegal characters
if (libPath.IndexOfAny(Path.GetInvalidPathChars()) >= 0)
throw new ArgumentException($"Invalid characters in library path: {libPath}");
} Try / catch
try
{
EngineExtend.InitEngine(engine, workDir, manifest.Library);
}
catch (Exception ex) when (ex.Message.Contains("library 字段"))
{
// Fallback: init without library paths
EngineExtend.InitEngine(engine, workDir, null);
TaskControl.Logger.LogWarning("Library paths failed to load, continuing without: {Message}", ex.Message);
} Prevention
- Validate all Library paths in manifest.json before engine initialization.
- Use Path.GetInvalidPathChars() to pre-check for illegal characters.
- Test library paths with Directory.Exists before passing to the engine.
When it happens
Trigger: Setting up a V8 script engine via EngineExtend when the manifest.json Library array contains a path that ScriptUtils.NormalizePath cannot resolve — illegal path characters, malformed relative paths, or missing directory segments.
Common situations: A script package's manifest.json has a Library entry with a typo, invalid characters (e.g. quotes, colons on Windows), or a path referencing a directory structure that doesn't exist relative to the script root.
Related errors
- manifest.json: name is required.
- manifest.json: version is required.
- manifest.json: main script is required.
- JavaScript没有设置Output输出
- {paramName} 必须是集合或 JS Array
AI-assisted analysis of babalae/better-genshin-impact@a7cb36712d (2026-08-13).
Data as JSON: /api/errors/07c2787edc9a4324.
Report an issue: GitHub.