{"record":{"id":"07c2787edc9a4324","repo":"babalae/better-genshin-impact","slug":"library-path-ex-message","errorCode":null,"errorMessage":"从 library 字段读取路径 '{path}' 失败: {ex.Message}","messagePattern":"从 library 字段读取路径 '(.+?)' 失败: (.+?)","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"BetterGenshinImpact/Core/Script/EngineExtend.cs","lineNumber":126,"sourceCode":"        engine.AddHostObject(\"htmlMask\", new HtmlMask(workDir));\n\n        // 导入 JavaScript 模块\n        // https://microsoft.github.io/ClearScript/2023/01/24/module-interop.html\n        // https://github.com/microsoft/ClearScript/blob/master/ClearScriptTest/V8ModuleTest.cs\n        engine.DocumentSettings.AccessFlags = DocumentAccessFlags.AllowCategoryMismatch;\n        if (searchPaths != null)\n        {\n            var normalizedPaths = new List<string>();\n            foreach (var path in searchPaths)\n            {\n                try\n                {\n                    var normalizedPath = ScriptUtils.NormalizePath(workDir, path);\n                    normalizedPaths.Add(normalizedPath);\n                }\n                catch (Exception ex)\n                {\n                    throw new Exception($\"从 library 字段读取路径 '{path}' 失败: {ex.Message}\", ex);\n                }\n            }\n\n            if (normalizedPaths.Count > 0)\n            {\n                engine.DocumentSettings.SearchPath = string.Join(';', normalizedPaths);\n            }\n        }\n    }\n\n    public static void AddAllGlobalMethod(IScriptEngine engine)\n    {\n        // // 获取GlobalMethod类的所有静态方法\n        // var methods = typeof(GlobalMethod).GetMethods(BindingFlags.Static | BindingFlags.Public);\n        //\n        // foreach (var method in methods)\n        // {\n        //     // 使用方法名首字母小写作为HostObject的名称","sourceCodeStart":108,"sourceCodeEnd":144,"githubUrl":"https://github.com/babalae/better-genshin-impact/blob/a7cb36712dcb409be610257d877fcea3597e9d6b/BetterGenshinImpact/Core/Script/EngineExtend.cs#L108-L144","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// manifest.json before\n\"library\": [\"..\\\\bad<>path\"]\n// after\n\"library\": [\"../shared/libs\"]","handlingStrategy":"validation","validationCode":"foreach (var libPath in manifest.Library)\n{\n    var full = Path.Combine(workDir, libPath);\n    if (!Directory.Exists(full))\n        throw new DirectoryNotFoundException($\"Library path not found: {full}\");\n    // Check for illegal characters\n    if (libPath.IndexOfAny(Path.GetInvalidPathChars()) >= 0)\n        throw new ArgumentException($\"Invalid characters in library path: {libPath}\");\n}","typeGuard":null,"tryCatchPattern":"try\n{\n    EngineExtend.InitEngine(engine, workDir, manifest.Library);\n}\ncatch (Exception ex) when (ex.Message.Contains(\"library 字段\"))\n{\n    // Fallback: init without library paths\n    EngineExtend.InitEngine(engine, workDir, null);\n    TaskControl.Logger.LogWarning(\"Library paths failed to load, continuing without: {Message}\", ex.Message);\n}","preventionTips":["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."],"tags":["configuration","path-resolution","clearscript","manifest"],"backgroundTag":null,"analyzedSha":"a7cb36712dcb409be610257d877fcea3597e9d6b","analyzedAt":"2026-08-13T16:44:57.548Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}