From e53e2424dd4551d2cb15612201041abee6c38a20 Mon Sep 17 00:00:00 2001 From: Kevin Knight <57677197+kevin-m-knight-gs@users.noreply.github.com> Date: Fri, 8 Nov 2024 18:03:57 -0500 Subject: [PATCH] Make call stack optional for PureExecutionException (#880) * Make call stack optional for PureExecutionException * Remove callStack argument from compiled mode PureExecutionException instantiation --- .../m3/exception/PureAssertFailException.java | 25 ++++ .../m3/exception/PureExecutionException.java | 93 +++++++++------ .../PureExecutionStreamingException.java | 13 ++- .../PureDynamicReactivateException.java | 15 ++- .../PureCompiledExecutionException.java | 5 +- .../processors/FunctionProcessor.java | 4 +- .../support/map/PureCacheMapGetException.java | 3 +- .../type/_class/ClassImplProcessor.java | 4 +- .../api/TestFunctionExecutionStart.java | 108 ++++++------------ .../ExecutionEndListenerStateException.java | 5 + .../shared/listeners/ExecutionListeners.java | 3 +- 11 files changed, 147 insertions(+), 131 deletions(-) diff --git a/legend-pure-core/legend-pure-m3-core/src/main/java/org/finos/legend/pure/m3/exception/PureAssertFailException.java b/legend-pure-core/legend-pure-m3-core/src/main/java/org/finos/legend/pure/m3/exception/PureAssertFailException.java index 648d7bc649..0dfedf8985 100644 --- a/legend-pure-core/legend-pure-m3-core/src/main/java/org/finos/legend/pure/m3/exception/PureAssertFailException.java +++ b/legend-pure-core/legend-pure-m3-core/src/main/java/org/finos/legend/pure/m3/exception/PureAssertFailException.java @@ -28,26 +28,51 @@ public PureAssertFailException(SourceInformation sourceInformation, String info, super(sourceInformation, info, cause, callStack); } + public PureAssertFailException(SourceInformation sourceInformation, String info, PureAssertFailException cause) + { + super(sourceInformation, info, cause); + } + public PureAssertFailException(SourceInformation sourceInformation, String info, MutableStack callStack) { super(sourceInformation, info, callStack); } + public PureAssertFailException(SourceInformation sourceInformation, String info) + { + super(sourceInformation, info); + } + public PureAssertFailException(SourceInformation sourceInformation, PureAssertFailException cause, MutableStack callStack) { super(sourceInformation, cause, callStack); } + public PureAssertFailException(SourceInformation sourceInformation, PureAssertFailException cause) + { + super(sourceInformation, cause); + } + public PureAssertFailException(String info, PureAssertFailException cause, MutableStack callStack) { super(info, cause, callStack); } + public PureAssertFailException(String info, PureAssertFailException cause) + { + super(info, cause); + } + public PureAssertFailException(String info, MutableStack callStack) { super(info, callStack); } + public PureAssertFailException(String info) + { + super(info); + } + public PureAssertFailException() { super(); diff --git a/legend-pure-core/legend-pure-m3-core/src/main/java/org/finos/legend/pure/m3/exception/PureExecutionException.java b/legend-pure-core/legend-pure-m3-core/src/main/java/org/finos/legend/pure/m3/exception/PureExecutionException.java index a0e23c5bc8..bedf7b45a4 100644 --- a/legend-pure-core/legend-pure-m3-core/src/main/java/org/finos/legend/pure/m3/exception/PureExecutionException.java +++ b/legend-pure-core/legend-pure-m3-core/src/main/java/org/finos/legend/pure/m3/exception/PureExecutionException.java @@ -23,15 +23,12 @@ import org.finos.legend.pure.m4.exception.PureException; import org.finos.legend.pure.m4.tools.SafeAppendable; -import java.io.IOException; -import java.util.function.Consumer; - /** * An exception raised when something goes wrong during Pure execution. */ public class PureExecutionException extends PureException { - private MutableStack callStack; + private final MutableStack callStack; public PureExecutionException(SourceInformation sourceInformation, String info, Throwable cause, MutableStack callStack) { @@ -39,45 +36,81 @@ public PureExecutionException(SourceInformation sourceInformation, String info, this.callStack = callStack; } + public PureExecutionException(SourceInformation sourceInformation, String info, Throwable cause) + { + this(sourceInformation, info, cause, null); + } + public PureExecutionException(SourceInformation sourceInformation, String info, MutableStack callStack) { super(sourceInformation, info, null); this.callStack = callStack; } + public PureExecutionException(SourceInformation sourceInformation, String info) + { + this(sourceInformation, info, (MutableStack) null); + } + public PureExecutionException(SourceInformation sourceInformation, Throwable cause, MutableStack callStack) { super(sourceInformation, null, cause); this.callStack = callStack; } + public PureExecutionException(SourceInformation sourceInformation, Throwable cause) + { + this(sourceInformation, cause, null); + } + public PureExecutionException(String info, Throwable cause, MutableStack callStack) { super(info, cause); this.callStack = callStack; } + public PureExecutionException(String info, Throwable cause) + { + this(info, cause, null); + } + public PureExecutionException(SourceInformation sourceInformation, MutableStack callStack) { super(sourceInformation); this.callStack = callStack; } + public PureExecutionException(SourceInformation sourceInformation) + { + this(sourceInformation, (MutableStack) null); + } + public PureExecutionException(String info, MutableStack callStack) { super(info); this.callStack = callStack; } + public PureExecutionException(String info) + { + this(info, (MutableStack) null); + } + public PureExecutionException(Throwable cause, MutableStack callStack) { super(cause); this.callStack = callStack; } + public PureExecutionException(Throwable cause) + { + this(cause, null); + } + public PureExecutionException() { super(); + this.callStack = null; } @Override @@ -94,41 +127,25 @@ public MutableStack getCallStack() public T printPureStackTrace(T appendable, String indent, ProcessorSupport processorSupport) { super.printPureStackTrace(appendable, indent); - try - { - appendable.append("\n"); - appendable.append(indent); - appendable.append("Full Stack:\n"); - getCallStack().toList().reverseThis().forEach((Consumer) - x -> - { - try - { - appendable.append(indent); - appendable.append(" "); - CoreInstance func = x.getValueForMetaPropertyToOne(M3Properties.func); - if (func != null) - { - FunctionDescriptor.writeFunctionDescriptor(appendable, func, false, processorSupport); - } - else - { - appendable.append("NULL / TODO"); - } - appendable.append(" <- "); - writeSourceInformationMessage(SafeAppendable.wrap(appendable), x.getSourceInformation(), false); - appendable.append("\n"); - } - catch (IOException e) - { - throw new RuntimeException(e); - } - }); - return appendable; - } - catch (IOException e) + if ((this.callStack != null) && this.callStack.notEmpty()) { - throw new RuntimeException(e); + SafeAppendable safeAppendable = SafeAppendable.wrap(appendable); + safeAppendable.append('\n').append(indent).append("Full Stack:"); + this.callStack.toList().reverseForEach(x -> + { + safeAppendable.append('\n').append(indent).append(" "); + CoreInstance func = x.getValueForMetaPropertyToOne(M3Properties.func); + if (func != null) + { + FunctionDescriptor.writeFunctionDescriptor(appendable, func, false, processorSupport); + } + else + { + safeAppendable.append("NULL / TODO"); + } + writeSourceInformationMessage(safeAppendable.append(" <- "), x.getSourceInformation(), false); + }); } + return appendable; } } diff --git a/legend-pure-core/legend-pure-m3-core/src/main/java/org/finos/legend/pure/m3/exception/PureExecutionStreamingException.java b/legend-pure-core/legend-pure-m3-core/src/main/java/org/finos/legend/pure/m3/exception/PureExecutionStreamingException.java index c68b72582b..b101b90caa 100644 --- a/legend-pure-core/legend-pure-m3-core/src/main/java/org/finos/legend/pure/m3/exception/PureExecutionStreamingException.java +++ b/legend-pure-core/legend-pure-m3-core/src/main/java/org/finos/legend/pure/m3/exception/PureExecutionStreamingException.java @@ -20,14 +20,19 @@ /** * Indicates that an exception was thrown while we were writing to the response * during lazy streaming execution - * + *

* This separate exception is provide, because we have already written data to the response, * so the error handling needs to be different */ public class PureExecutionStreamingException extends PureExecutionException { public PureExecutionStreamingException(Throwable cause, MutableStack callStack) - { - super(cause, callStack); - } + { + super(cause, callStack); + } + + public PureExecutionStreamingException(Throwable cause) + { + super(cause); + } } diff --git a/legend-pure-runtime/legend-pure-runtime-java-engine-compiled/src/main/java/org/finos/legend/pure/runtime/java/compiled/compiler/PureDynamicReactivateException.java b/legend-pure-runtime/legend-pure-runtime-java-engine-compiled/src/main/java/org/finos/legend/pure/runtime/java/compiled/compiler/PureDynamicReactivateException.java index b7a629496b..cc6f6f69d4 100644 --- a/legend-pure-runtime/legend-pure-runtime-java-engine-compiled/src/main/java/org/finos/legend/pure/runtime/java/compiled/compiler/PureDynamicReactivateException.java +++ b/legend-pure-runtime/legend-pure-runtime-java-engine-compiled/src/main/java/org/finos/legend/pure/runtime/java/compiled/compiler/PureDynamicReactivateException.java @@ -14,7 +14,6 @@ package org.finos.legend.pure.runtime.java.compiled.compiler; -import org.eclipse.collections.api.factory.Stacks; import org.finos.legend.pure.m3.exception.PureExecutionException; import org.finos.legend.pure.m4.coreinstance.SourceInformation; @@ -22,37 +21,37 @@ public class PureDynamicReactivateException extends PureExecutionException { public PureDynamicReactivateException(SourceInformation sourceInformation, String info, Throwable cause) { - super(sourceInformation, info, cause, Stacks.mutable.empty()); + super(sourceInformation, info, cause); } public PureDynamicReactivateException(SourceInformation sourceInformation, String info) { - super(sourceInformation, info, null); + super(sourceInformation, info); } public PureDynamicReactivateException(SourceInformation sourceInformation, Throwable cause) { - super(sourceInformation, null, cause, Stacks.mutable.empty()); + super(sourceInformation, null, cause); } public PureDynamicReactivateException(String info, Throwable cause) { - super(info, cause, Stacks.mutable.empty()); + super(info, cause); } public PureDynamicReactivateException(SourceInformation sourceInformation) { - super(sourceInformation, Stacks.mutable.empty()); + super(sourceInformation); } public PureDynamicReactivateException(String info) { - super(info, Stacks.mutable.empty()); + super(info); } public PureDynamicReactivateException(Throwable cause) { - super(cause, Stacks.mutable.empty()); + super(cause); } public PureDynamicReactivateException() diff --git a/legend-pure-runtime/legend-pure-runtime-java-engine-compiled/src/main/java/org/finos/legend/pure/runtime/java/compiled/execution/sourceInformation/PureCompiledExecutionException.java b/legend-pure-runtime/legend-pure-runtime-java-engine-compiled/src/main/java/org/finos/legend/pure/runtime/java/compiled/execution/sourceInformation/PureCompiledExecutionException.java index c09f94089c..6a1d0bd8b6 100644 --- a/legend-pure-runtime/legend-pure-runtime-java-engine-compiled/src/main/java/org/finos/legend/pure/runtime/java/compiled/execution/sourceInformation/PureCompiledExecutionException.java +++ b/legend-pure-runtime/legend-pure-runtime-java-engine-compiled/src/main/java/org/finos/legend/pure/runtime/java/compiled/execution/sourceInformation/PureCompiledExecutionException.java @@ -15,7 +15,6 @@ package org.finos.legend.pure.runtime.java.compiled.execution.sourceInformation; import org.eclipse.collections.api.factory.Lists; -import org.eclipse.collections.api.factory.Stacks; import org.eclipse.collections.api.list.MutableList; import org.finos.legend.pure.m3.exception.PureExecutionException; import org.finos.legend.pure.m4.coreinstance.SourceInformation; @@ -27,14 +26,14 @@ public class PureCompiledExecutionException extends PureExecutionException public PureCompiledExecutionException(SourceInformation sourceInformation, String info, Throwable cause) { - super(sourceInformation, info, cause, Stacks.mutable.empty()); + super(sourceInformation, info, cause); addStackTraceElement(sourceInformation); } @SuppressWarnings("unused") public PureCompiledExecutionException(SourceInformation sourceInformation, String info) { - super(sourceInformation, info, null); + super(sourceInformation, info); addStackTraceElement(sourceInformation); } diff --git a/legend-pure-runtime/legend-pure-runtime-java-engine-compiled/src/main/java/org/finos/legend/pure/runtime/java/compiled/generation/processors/FunctionProcessor.java b/legend-pure-runtime/legend-pure-runtime-java-engine-compiled/src/main/java/org/finos/legend/pure/runtime/java/compiled/generation/processors/FunctionProcessor.java index 7a4af7633e..b08de83362 100644 --- a/legend-pure-runtime/legend-pure-runtime-java-engine-compiled/src/main/java/org/finos/legend/pure/runtime/java/compiled/generation/processors/FunctionProcessor.java +++ b/legend-pure-runtime/legend-pure-runtime-java-engine-compiled/src/main/java/org/finos/legend/pure/runtime/java/compiled/generation/processors/FunctionProcessor.java @@ -66,7 +66,7 @@ public static String processFunctionDefinition(CoreInstance functionDefinition, CoreInstance definition = Instance.getValueForMetaPropertyToOneResolved(constraint, M3Properties.functionDefinition, processorContext.getSupport()); String eval = "(Boolean) " + ValueSpecificationProcessor.createFunctionForLambda(constraint, definition, processorContext.getSupport(), processorContext) + ".execute(Lists.mutable.with(" + stringParams + "),es)"; String ruleId = Instance.getValueForMetaPropertyToOneResolved(constraint, M3Properties.name, processorContext.getSupport()).getName(); - return "if(! (" + eval + ")){throw new org.finos.legend.pure.m3.exception.PureExecutionException(_sourceInformation, \"Constraint (PRE):[" + ruleId + "] violated. (Function:" + functionDefinition.getName() + ")\", org.eclipse.collections.api.factory.Stacks.mutable.empty());}\n"; + return "if(! (" + eval + ")){throw new org.finos.legend.pure.m3.exception.PureExecutionException(_sourceInformation, \"Constraint (PRE):[" + ruleId + "] violated. (Function:" + functionDefinition.getName() + ")\");}\n"; }).makeString("") + " final " + returnType + " _return = " + IdBuilder.sourceToId(functionDefinition.getSourceInformation()) + "." + functionNameToJava(functionDefinition) + "(" + functionType.getValueForMetaPropertyToMany("parameters").collect(ci -> "_" + ci.getValueForMetaPropertyToOne(M3Properties.name).getName()).makeString(", ") + ", es);\n" + @@ -75,7 +75,7 @@ public static String processFunctionDefinition(CoreInstance functionDefinition, CoreInstance definition = Instance.getValueForMetaPropertyToOneResolved(constraint, M3Properties.functionDefinition, processorContext.getSupport()); String eval = "(Boolean) " + ValueSpecificationProcessor.createFunctionForLambda(constraint, definition, processorContext.getSupport(), processorContext) + ".execute(Lists.mutable.with(" + stringParams + ",_return),es)"; String ruleId = Instance.getValueForMetaPropertyToOneResolved(constraint, M3Properties.name, processorContext.getSupport()).getName(); - return "if(! (" + eval + ")){throw new org.finos.legend.pure.m3.exception.PureExecutionException(_sourceInformation, \"Constraint (POST):[" + ruleId + "] violated. (Function:" + functionDefinition.getName() + ")\", org.eclipse.collections.api.factory.Stacks.mutable.empty());}\n"; + return "if(! (" + eval + ")){throw new org.finos.legend.pure.m3.exception.PureExecutionException(_sourceInformation, \"Constraint (POST):[" + ruleId + "] violated. (Function:" + functionDefinition.getName() + ")\");}\n"; }).makeString("") + "return _return;" + diff --git a/legend-pure-runtime/legend-pure-runtime-java-engine-compiled/src/main/java/org/finos/legend/pure/runtime/java/compiled/generation/processors/support/map/PureCacheMapGetException.java b/legend-pure-runtime/legend-pure-runtime-java-engine-compiled/src/main/java/org/finos/legend/pure/runtime/java/compiled/generation/processors/support/map/PureCacheMapGetException.java index c55ee1e19c..7076dab66b 100644 --- a/legend-pure-runtime/legend-pure-runtime-java-engine-compiled/src/main/java/org/finos/legend/pure/runtime/java/compiled/generation/processors/support/map/PureCacheMapGetException.java +++ b/legend-pure-runtime/legend-pure-runtime-java-engine-compiled/src/main/java/org/finos/legend/pure/runtime/java/compiled/generation/processors/support/map/PureCacheMapGetException.java @@ -14,7 +14,6 @@ package org.finos.legend.pure.runtime.java.compiled.generation.processors.support.map; -import org.eclipse.collections.api.factory.Stacks; import org.finos.legend.pure.m3.exception.PureExecutionException; import org.finos.legend.pure.m4.exception.PureException; @@ -24,7 +23,7 @@ public class PureCacheMapGetException extends PureExecutionException PureCacheMapGetException(Object key, Throwable cause) { - super(generateInfo(key, cause), cause, Stacks.mutable.empty()); + super(generateInfo(key, cause), cause); this.key = key; } diff --git a/legend-pure-runtime/legend-pure-runtime-java-engine-compiled/src/main/java/org/finos/legend/pure/runtime/java/compiled/generation/processors/type/_class/ClassImplProcessor.java b/legend-pure-runtime/legend-pure-runtime-java-engine-compiled/src/main/java/org/finos/legend/pure/runtime/java/compiled/generation/processors/type/_class/ClassImplProcessor.java index cd2705419a..f770cd19d6 100644 --- a/legend-pure-runtime/legend-pure-runtime-java-engine-compiled/src/main/java/org/finos/legend/pure/runtime/java/compiled/generation/processors/type/_class/ClassImplProcessor.java +++ b/legend-pure-runtime/legend-pure-runtime-java-engine-compiled/src/main/java/org/finos/legend/pure/runtime/java/compiled/generation/processors/type/_class/ClassImplProcessor.java @@ -358,7 +358,7 @@ public static String buildSimpleConstructor(CoreInstance _class, String classNam return " public " + className + "(String id)\n" + " {\n" + " super(id);\n" + - (Type.isBottomType(_class, processorSupport) ? " throw new org.finos.legend.pure.m3.exception.PureExecutionException(\"Cannot instantiate " + PackageableElement.getUserPathForPackageableElement(_class, "::") + "\", org.eclipse.collections.api.factory.Stacks.mutable.empty());\n" : "") + + (Type.isBottomType(_class, processorSupport) ? " throw new org.finos.legend.pure.m3.exception.PureExecutionException(\"Cannot instantiate " + PackageableElement.getUserPathForPackageableElement(_class, "::") + "\");\n" : "") + " }\n" + "\n"; } @@ -1038,7 +1038,7 @@ public static String validate(boolean stateAndDeep, CoreInstance _class, String return " if (!(" + eval + "))\n" + " {\n" + - " throw new org.finos.legend.pure.m3.exception.PureExecutionException(sourceInformation, " + errorMessage + ", org.eclipse.collections.api.factory.Stacks.mutable.empty());\n" + + " throw new org.finos.legend.pure.m3.exception.PureExecutionException(sourceInformation, " + errorMessage + ");\n" + " }\n"; } else diff --git a/legend-pure-runtime/legend-pure-runtime-java-engine-interpreted/src/test/java/org/finos/legend/pure/runtime/java/interpreted/runtime/api/TestFunctionExecutionStart.java b/legend-pure-runtime/legend-pure-runtime-java-engine-interpreted/src/test/java/org/finos/legend/pure/runtime/java/interpreted/runtime/api/TestFunctionExecutionStart.java index f90d430d9e..d7cbaf02c8 100644 --- a/legend-pure-runtime/legend-pure-runtime-java-engine-interpreted/src/test/java/org/finos/legend/pure/runtime/java/interpreted/runtime/api/TestFunctionExecutionStart.java +++ b/legend-pure-runtime/legend-pure-runtime-java-engine-interpreted/src/test/java/org/finos/legend/pure/runtime/java/interpreted/runtime/api/TestFunctionExecutionStart.java @@ -15,10 +15,9 @@ package org.finos.legend.pure.runtime.java.interpreted.runtime.api; import org.eclipse.collections.api.factory.Lists; -import org.finos.legend.pure.m3.tests.AbstractPureTestWithCoreCompiled; import org.finos.legend.pure.m3.exception.PureExecutionException; import org.finos.legend.pure.m3.navigation.ValueSpecificationBootstrap; -import org.finos.legend.pure.m3.execution.FunctionExecution; +import org.finos.legend.pure.m3.tests.AbstractPureTestWithCoreCompiled; import org.finos.legend.pure.m4.coreinstance.CoreInstance; import org.finos.legend.pure.runtime.java.interpreted.FunctionExecutionInterpreted; import org.junit.After; @@ -28,12 +27,10 @@ public class TestFunctionExecutionStart extends AbstractPureTestWithCoreCompiled { - static FunctionExecutionInterpreted functionExecution = new FunctionExecutionInterpreted(); - @BeforeClass public static void setUp() { - setUpRuntime(getFunctionExecution()); + setUpRuntime(new FunctionExecutionInterpreted()); } @After @@ -50,32 +47,20 @@ public void testStartWithNotEnoughArguments() CoreInstance func = runtime.getFunction("testFn(String[1], String[1]):String[1]"); Assert.assertNotNull(func); - try - { - functionExecution.start(func, Lists.immutable.with()); - } - catch (Exception e) - { - assertPureException(PureExecutionException.class, "Error executing the function:testFn(String[1], String[1]):String[1]. Mismatch between the number of function parameters (2) and the number of supplied arguments (0)\n", e); - } + PureExecutionException e1 = Assert.assertThrows(PureExecutionException.class, () -> functionExecution.start(func, Lists.immutable.with())); + assertPureException(PureExecutionException.class, "Error executing the function:testFn(String[1], String[1]):String[1]. Mismatch between the number of function parameters (2) and the number of supplied arguments (0)\n", e1); - try - { - functionExecution.start(func, Lists.immutable.with(ValueSpecificationBootstrap.newStringLiteral(repository, "string", processorSupport))); - } - catch (Exception e) - { - assertPureException(PureExecutionException.class, "Error executing the function:testFn(String[1], String[1]):String[1]. Mismatch between the number of function parameters (2) and the number of supplied arguments (1)\n" + - "Anonymous_StripedId instance InstanceValue\n" + - " genericType(Property):\n" + - " Anonymous_StripedId instance GenericType\n" + - " rawType(Property):\n" + - " String instance PrimitiveType\n" + - " multiplicity(Property):\n" + - " PureOne instance PackageableMultiplicity\n" + - " values(Property):\n" + - " string instance String", e); - } + PureExecutionException e2 = Assert.assertThrows(PureExecutionException.class, () -> functionExecution.start(func, Lists.immutable.with(ValueSpecificationBootstrap.newStringLiteral(repository, "string", processorSupport)))); + assertPureException(PureExecutionException.class, "Error executing the function:testFn(String[1], String[1]):String[1]. Mismatch between the number of function parameters (2) and the number of supplied arguments (1)\n" + + "Anonymous_StripedId instance InstanceValue\n" + + " genericType(Property):\n" + + " Anonymous_StripedId instance GenericType\n" + + " rawType(Property):\n" + + " String instance PrimitiveType\n" + + " multiplicity(Property):\n" + + " PureOne instance PackageableMultiplicity\n" + + " values(Property):\n" + + " string instance String", e2); } @Test @@ -84,23 +69,18 @@ public void testStartWithTooManyArguments() compileTestSource("fromString.pure", "function testFn():String[1] { 'the quick brown fox jumps over the lazy dog' }"); CoreInstance func = runtime.getFunction("testFn():String[1]"); Assert.assertNotNull(func); - try - { - functionExecution.start(func, Lists.mutable.with(ValueSpecificationBootstrap.newStringLiteral(repository, "string", processorSupport))); - } - catch (Exception e) - { - assertPureException(PureExecutionException.class, "Error executing the function:testFn():String[1]. Mismatch between the number of function parameters (0) and the number of supplied arguments (1)\n" + - "Anonymous_StripedId instance InstanceValue\n" + - " genericType(Property):\n" + - " Anonymous_StripedId instance GenericType\n" + - " rawType(Property):\n" + - " String instance PrimitiveType\n" + - " multiplicity(Property):\n" + - " PureOne instance PackageableMultiplicity\n" + - " values(Property):\n" + - " string instance String", e); - } + + PureExecutionException e = Assert.assertThrows(PureExecutionException.class, () -> functionExecution.start(func, Lists.mutable.with(ValueSpecificationBootstrap.newStringLiteral(repository, "string", processorSupport)))); + assertPureException(PureExecutionException.class, "Error executing the function:testFn():String[1]. Mismatch between the number of function parameters (0) and the number of supplied arguments (1)\n" + + "Anonymous_StripedId instance InstanceValue\n" + + " genericType(Property):\n" + + " Anonymous_StripedId instance GenericType\n" + + " rawType(Property):\n" + + " String instance PrimitiveType\n" + + " multiplicity(Property):\n" + + " PureOne instance PackageableMultiplicity\n" + + " values(Property):\n" + + " string instance String", e); } @Test @@ -136,29 +116,17 @@ public void testCallStackInExecutionExceptionPure() "{" + " fail();" + "}"); - try - { - this.execute("go():Boolean[1]"); - } - catch (PureExecutionException e) - { - StringBuffer buffer = new StringBuffer(); - e.printPureStackTrace(buffer," ", functionExecution.getProcessorSupport()); - Assert.assertEquals( - " 1: resource:/platform/pure/essential/tests/assert.pure line:26 column:5\n" + - "\n" + - " Full Stack:\n" + - " nest():Boolean[1] <- resource:fromString.pure line:4 column:8\n" + - " fail():Boolean[1] <- resource:fromString.pure line:7 column:31\n" + - " assert(Boolean[1]):Boolean[1] <- resource:/platform/pure/essential/tests/fail.pure line:19 column:5\n" + - " assert(Boolean[1], String[1]):Boolean[1] <- resource:/platform/pure/essential/tests/assert.pure line:31 column:5\n" + - " assert(Boolean[1], Function<{->String[1]}>[1]):Boolean[1] <- resource:/platform/pure/essential/tests/assert.pure line:26 column:5\n", buffer.toString()); - } - } - - protected static FunctionExecution getFunctionExecution() - { - return functionExecution; + PureExecutionException e = Assert.assertThrows(PureExecutionException.class, () -> execute("go():Boolean[1]")); + String trace = e.printPureStackTrace(new StringBuilder(), " ", functionExecution.getProcessorSupport()).toString(); + Assert.assertEquals( + " 1: resource:/platform/pure/essential/tests/assert.pure line:26 column:5\n" + + "\n" + + " Full Stack:\n" + + " nest():Boolean[1] <- resource:fromString.pure line:4 column:8\n" + + " fail():Boolean[1] <- resource:fromString.pure line:7 column:31\n" + + " assert(Boolean[1]):Boolean[1] <- resource:/platform/pure/essential/tests/fail.pure line:19 column:5\n" + + " assert(Boolean[1], String[1]):Boolean[1] <- resource:/platform/pure/essential/tests/assert.pure line:31 column:5\n" + + " assert(Boolean[1], Function<{->String[1]}>[1]):Boolean[1] <- resource:/platform/pure/essential/tests/assert.pure line:26 column:5", trace); } } diff --git a/legend-pure-runtime/legend-pure-runtime-java-engine-shared/src/main/java/org/finos/legend/pure/runtime/java/shared/listeners/ExecutionEndListenerStateException.java b/legend-pure-runtime/legend-pure-runtime-java-engine-shared/src/main/java/org/finos/legend/pure/runtime/java/shared/listeners/ExecutionEndListenerStateException.java index 867e6e660c..687e484215 100644 --- a/legend-pure-runtime/legend-pure-runtime-java-engine-shared/src/main/java/org/finos/legend/pure/runtime/java/shared/listeners/ExecutionEndListenerStateException.java +++ b/legend-pure-runtime/legend-pure-runtime-java-engine-shared/src/main/java/org/finos/legend/pure/runtime/java/shared/listeners/ExecutionEndListenerStateException.java @@ -24,4 +24,9 @@ public class ExecutionEndListenerStateException extends PureExecutionException { super(info, functionExpressionCallStack); } + + ExecutionEndListenerStateException(String info) + { + super(info); + } } diff --git a/legend-pure-runtime/legend-pure-runtime-java-engine-shared/src/main/java/org/finos/legend/pure/runtime/java/shared/listeners/ExecutionListeners.java b/legend-pure-runtime/legend-pure-runtime-java-engine-shared/src/main/java/org/finos/legend/pure/runtime/java/shared/listeners/ExecutionListeners.java index 5f8229fa75..84e358f865 100644 --- a/legend-pure-runtime/legend-pure-runtime-java-engine-shared/src/main/java/org/finos/legend/pure/runtime/java/shared/listeners/ExecutionListeners.java +++ b/legend-pure-runtime/legend-pure-runtime-java-engine-shared/src/main/java/org/finos/legend/pure/runtime/java/shared/listeners/ExecutionListeners.java @@ -17,7 +17,6 @@ import org.eclipse.collections.api.factory.Lists; import org.eclipse.collections.api.factory.Stacks; import org.eclipse.collections.api.list.MutableList; -import org.eclipse.collections.api.stack.MutableStack; import org.finos.legend.pure.m3.exception.PureExecutionException; import java.util.Objects; @@ -102,7 +101,7 @@ public void executionEnd(Exception exception) throwables.add(state.getThrowable()); } }); - ExecutionEndListenerStateException toThrow = new ExecutionEndListenerStateException(builder.toString(), Stacks.mutable.empty()); + ExecutionEndListenerStateException toThrow = new ExecutionEndListenerStateException(builder.toString()); throwables.forEach(toThrow::addSuppressed); throw toThrow; }