feat: 脚本下载/编辑接口、前端Groovy编辑器、Groovy错误行号提取
This commit is contained in:
@@ -41,7 +41,7 @@ public class GroovyScriptEngine {
|
||||
return buildResult(result, scriptResult);
|
||||
} catch (Exception e) {
|
||||
result.put("matched", false);
|
||||
result.put("message", "Groovy 脚本执行异常: " + e.getMessage());
|
||||
result.put("message", extractGroovyError(e));
|
||||
log.error("Groovy error for url={}", url, e);
|
||||
}
|
||||
return result;
|
||||
@@ -91,6 +91,25 @@ public class GroovyScriptEngine {
|
||||
return result;
|
||||
}
|
||||
|
||||
/** 从 Groovy 异常中提取含行号的错误信息 */
|
||||
private String extractGroovyError(Exception e) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(e.getMessage() != null ? e.getMessage() : e.getClass().getSimpleName());
|
||||
for (StackTraceElement ste : e.getStackTrace()) {
|
||||
String cn = ste.getClassName();
|
||||
// Groovy 编译后的类名通常是 Script1, Script2 或用户脚本类
|
||||
if (cn.startsWith("Script") || cn.contains("$_run_closure") || cn.contains("$__execute")) {
|
||||
sb.append("\n at line ").append(ste.getLineNumber());
|
||||
if (ste.getFileName() != null) sb.append(" (").append(ste.getFileName()).append(")");
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (e.getCause() != null && e.getCause() != e) {
|
||||
sb.append("\nCaused by: ").append(e.getCause().getMessage());
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public static class JsoupHelper {
|
||||
public Object parse(String html) { return Jsoup.parse(html); }
|
||||
public Object parse(String html, String baseUri) { return Jsoup.parse(html, baseUri); }
|
||||
|
||||
Reference in New Issue
Block a user