bug #I631ZF groovy脚本接入时,自定义异常抛出后被组件失败异常覆盖

This commit is contained in:
everywhere.z
2022-11-30 16:25:08 +08:00
parent 8286bf7eae
commit 2bd8e0a86b
8 changed files with 100 additions and 4 deletions

View File

@@ -100,7 +100,6 @@ public class GraalJavaScriptExecutor implements ScriptExecutor {
}
return value;
} catch (Exception e){
log.error(e.getMessage(), e);
throw e;
}
}

View File

@@ -4,6 +4,7 @@ import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.yomahub.liteflow.exception.LiteFlowException;
import com.yomahub.liteflow.script.ScriptBeanManager;
import com.yomahub.liteflow.script.ScriptExecuteWrap;
import com.yomahub.liteflow.slot.DataBus;
@@ -92,8 +93,11 @@ public class GroovyScriptExecutor implements ScriptExecutor {
return compiledScript.eval(bindings);
}catch (Exception e){
log.error(e.getMessage(), e);
throw e;
if (ObjectUtil.isNotNull(e.getCause()) && e.getCause() instanceof LiteFlowException){
throw (LiteFlowException)e.getCause();
}else{
throw e;
}
}
}

View File

@@ -91,7 +91,6 @@ public class JavaScriptExecutor implements ScriptExecutor {
return compiledScript.eval(bindings);
}catch (Exception e){
log.error(e.getMessage(), e);
throw e;
}
}

View File

@@ -0,0 +1,13 @@
package com.yomahub.liteflow.test.script.groovy.throwException;
import com.yomahub.liteflow.exception.LiteFlowException;
public class TestException extends LiteFlowException {
public TestException(String message) {
super(message);
}
public TestException(String code, String message) {
super(code, message);
}
}

View File

@@ -0,0 +1,39 @@
package com.yomahub.liteflow.test.script.groovy.throwException;
import com.yomahub.liteflow.core.FlowExecutor;
import com.yomahub.liteflow.flow.LiteflowResponse;
import com.yomahub.liteflow.slot.DefaultContext;
import com.yomahub.liteflow.test.BaseTest;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.junit4.SpringRunner;
import javax.annotation.Resource;
/**
* 测试springboot下的groovy脚本抛错
* @author Bryan.Zhang
* @since 2.9.4
*/
@RunWith(SpringRunner.class)
@TestPropertySource(value = "classpath:/throwException/application.properties")
@SpringBootTest(classes = ThrowExceptionScriptGroovyELTest.class)
@EnableAutoConfiguration
@ComponentScan({"com.yomahub.liteflow.test.script.groovy.throwException.cmp"})
public class ThrowExceptionScriptGroovyELTest extends BaseTest {
@Resource
private FlowExecutor flowExecutor;
@Test
public void test1(){
LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg");
Assert.assertFalse(response.isSuccess());
Assert.assertEquals("T01", response.getCode());
}
}

View File

@@ -0,0 +1,20 @@
/**
* <p>Title: liteflow</p>
* <p>Description: 轻量级的组件式流程框架</p>
* @author Bryan.Zhang
* @email weenyc31@163.com
* @Date 2020/4/1
*/
package com.yomahub.liteflow.test.script.groovy.throwException.cmp;
import com.yomahub.liteflow.annotation.LiteflowComponent;
import com.yomahub.liteflow.core.NodeComponent;
@LiteflowComponent("a")
public class ACmp extends NodeComponent {
@Override
public void process() {
System.out.println("ACmp executed!");
}
}

View File

@@ -0,0 +1 @@
liteflow.rule-source=throwException/flow.xml

View File

@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<flow>
<nodes>
<node id="s1" name="普通脚本1" type="script" language="groovy">
<![CDATA[
import cn.hutool.core.date.DateUtil
import com.yomahub.liteflow.test.script.groovy.throwException.TestException
def date = DateUtil.parse("2022-10-17 13:31:43")
println(date)
defaultContext.setData("demoDate", date)
throw new TestException("T01", "测试错误")
]]>
</node>
</nodes>
<chain name="chain1">
THEN(a, s1);
</chain>
</flow>