babalae/better-genshin-impact · error · Exception
JavaScript execution error: {ex.Message}
Error message
JavaScript execution error: {ex.Message} What it means
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.
Source
Thrown at BetterGenshinImpact/GameTask/AutoArtifactSalvage/AutoArtifactSalvageTask.cs:502
{
throw new InvalidOperationException("JavaScript没有设置Output输出");
}
if (engine.Script.Output is not bool)
{
throw new InvalidOperationException("JavaScript的Output输出不是布尔类型");
}
return (bool)engine.Script.Output;
}
catch (ScriptInterruptedException)
{
logger.LogWarning("脚本执行超出3秒限制,请使用正确的JS代码(JavaScript execution timeout!)");
throw;
}
catch (ScriptEngineException ex)
{
throw new Exception($"JavaScript execution error: {ex.Message}", ex);
}
}
public static bool IsMatchRegularExpression(string affixes, string regularExpression, out string msg)
{
Match match = Regex.Match(affixes, regularExpression);
if (match.Success)
{
if (string.IsNullOrEmpty(match.Value))
{
msg = "匹配成功!";
}
else
{
msg = $"匹配成功:{match.Value}";
}
}
elseView on GitHub (pinned to a7cb36712d)
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.
Example fix
// before
await Task.Run(() => engine.Execute(javaScript));
catch (ScriptEngineException ex) { throw new Exception($"JavaScript execution error: {ex.Message}", ex); }
// after - surface line info
catch (ScriptEngineException ex)
{
throw new Exception($"JavaScript execution error: {ex.Message}\n{ex.ErrorDetails}", ex);
} Defensive patterns
Strategy: try-catch
Validate before calling
try { Jint.Engine e = new(); e.Execute(js); } catch { /* reject before passing to ClearScript */ } Try / catch
try { await Task.Run(() => engine.Execute(javaScript)); }
catch (ScriptEngineException ex) { throw new Exception($"JavaScript execution error: {ex.ErrorDetails ?? ex.Message}", ex); } Prevention
- Lint/parse JS before execution.
- Surface ScriptEngineException.ErrorDetails for line/column.
- Document the available globals (ArtifactStat) for script authors.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- JavaScript没有设置Output输出
- JavaScript的Output输出不是布尔类型
- 无法解析模块导入路径: '{specifier}'
- 不支持的模块导入类型: '{specifier}' (仅支持 .js 文件)
- {paramName} 必须是集合或 JS Array
AI-assisted analysis of babalae/better-genshin-impact@a7cb36712d (2026-08-13).
Data as JSON: /api/errors/e2fbdc15af23c45c.
Report an issue: GitHub.