{"record":{"id":"e2fbdc15af23c45c","repo":"babalae/better-genshin-impact","slug":"javascript-execution-error-ex-message","errorCode":null,"errorMessage":"JavaScript execution error: {ex.Message}","messagePattern":"JavaScript execution error: (.+?)","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"BetterGenshinImpact/GameTask/AutoArtifactSalvage/AutoArtifactSalvageTask.cs","lineNumber":502,"sourceCode":"            {\n                throw new InvalidOperationException(\"JavaScript没有设置Output输出\");\n            }\n\n            if (engine.Script.Output is not bool)\n            {\n                throw new InvalidOperationException(\"JavaScript的Output输出不是布尔类型\");\n            }\n\n            return (bool)engine.Script.Output;\n        }\n        catch (ScriptInterruptedException)\n        {\n            logger.LogWarning(\"脚本执行超出3秒限制，请使用正确的JS代码（JavaScript execution timeout!）\");\n            throw;\n        }\n        catch (ScriptEngineException ex)\n        {\n            throw new Exception($\"JavaScript execution error: {ex.Message}\", ex);\n        }\n    }\n\n    public static bool IsMatchRegularExpression(string affixes, string regularExpression, out string msg)\n    {\n        Match match = Regex.Match(affixes, regularExpression);\n        if (match.Success)\n        {\n            if (string.IsNullOrEmpty(match.Value))\n            {\n                msg = \"匹配成功！\";\n            }\n            else\n            {\n                msg = $\"匹配成功：{match.Value}\";\n            }\n        }\n        else","sourceCodeStart":484,"sourceCodeEnd":520,"githubUrl":"https://github.com/babalae/better-genshin-impact/blob/a7cb36712dcb409be610257d877fcea3597e9d6b/BetterGenshinImpact/GameTask/AutoArtifactSalvage/AutoArtifactSalvageTask.cs#L484-L520","documentation":"Wraps a ClearScript ScriptEngineException thrown during engine.Execute(javaScript). ScriptEngineException fires on JS syntax errors, runtime errors (TypeError, ReferenceError), or host-call failures. The wrapper flattens it into a generic System.Exception carrying the engine's message and inner exception.","triggerScenarios":"JS has a syntax error (missing brace, bad token); references an undefined variable; calls a host method that throws; uses unsupported ES features for the V8 version bundled with ClearScript.","commonSituations":"User-typed JS with typos; script assumes a global (like 'console' or 'require') not provided by ClearScript; version drift in the ClearScript/V8 engine changing supported syntax.","solutions":["Read ex.Message (and the inner ScriptEngineException.ErrorDetails if available) to find the JS line/column.","Validate/lint the JS before passing it to IsMatchJavaScript.","Wrap risky host interactions in try/catch inside the JS.","Provide a documented set of available globals (ArtifactStat) and a template."],"exampleFix":"// before\nawait Task.Run(() => engine.Execute(javaScript));\ncatch (ScriptEngineException ex) { throw new Exception($\"JavaScript execution error: {ex.Message}\", ex); }\n// after - surface line info\ncatch (ScriptEngineException ex)\n{\n    throw new Exception($\"JavaScript execution error: {ex.Message}\\n{ex.ErrorDetails}\", ex);\n}","handlingStrategy":"try-catch","validationCode":"try { Jint.Engine e = new(); e.Execute(js); } catch { /* reject before passing to ClearScript */ }","typeGuard":null,"tryCatchPattern":"try { await Task.Run(() => engine.Execute(javaScript)); }\ncatch (ScriptEngineException ex) { throw new Exception($\"JavaScript execution error: {ex.ErrorDetails ?? ex.Message}\", ex); }","preventionTips":["Lint/parse JS before execution.","Surface ScriptEngineException.ErrorDetails for line/column.","Document the available globals (ArtifactStat) for script authors."],"tags":["game-task","javascript","clearscript","script-error"],"backgroundTag":null,"analyzedSha":"a7cb36712dcb409be610257d877fcea3597e9d6b","analyzedAt":"2026-08-13T16:44:57.548Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}