Skip to content

Commit

Permalink
Make call stack optional for PureExecutionException (#880)
Browse files Browse the repository at this point in the history
* Make call stack optional for PureExecutionException

* Remove callStack argument from compiled mode PureExecutionException instantiation
  • Loading branch information
kevin-m-knight-gs authored Nov 8, 2024
1 parent e29e4ca commit e53e242
Show file tree
Hide file tree
Showing 11 changed files with 147 additions and 131 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<CoreInstance> callStack)
{
super(sourceInformation, info, callStack);
}

public PureAssertFailException(SourceInformation sourceInformation, String info)
{
super(sourceInformation, info);
}

public PureAssertFailException(SourceInformation sourceInformation, PureAssertFailException cause, MutableStack<CoreInstance> callStack)
{
super(sourceInformation, cause, callStack);
}

public PureAssertFailException(SourceInformation sourceInformation, PureAssertFailException cause)
{
super(sourceInformation, cause);
}

public PureAssertFailException(String info, PureAssertFailException cause, MutableStack<CoreInstance> callStack)
{
super(info, cause, callStack);
}

public PureAssertFailException(String info, PureAssertFailException cause)
{
super(info, cause);
}

public PureAssertFailException(String info, MutableStack<CoreInstance> callStack)
{
super(info, callStack);
}

public PureAssertFailException(String info)
{
super(info);
}

public PureAssertFailException()
{
super();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,61 +23,94 @@
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<CoreInstance> callStack;
private final MutableStack<CoreInstance> callStack;

public PureExecutionException(SourceInformation sourceInformation, String info, Throwable cause, MutableStack<CoreInstance> callStack)
{
super(sourceInformation, info, cause);
this.callStack = callStack;
}

public PureExecutionException(SourceInformation sourceInformation, String info, Throwable cause)
{
this(sourceInformation, info, cause, null);
}

public PureExecutionException(SourceInformation sourceInformation, String info, MutableStack<CoreInstance> callStack)
{
super(sourceInformation, info, null);
this.callStack = callStack;
}

public PureExecutionException(SourceInformation sourceInformation, String info)
{
this(sourceInformation, info, (MutableStack<CoreInstance>) null);
}

public PureExecutionException(SourceInformation sourceInformation, Throwable cause, MutableStack<CoreInstance> 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<CoreInstance> callStack)
{
super(info, cause);
this.callStack = callStack;
}

public PureExecutionException(String info, Throwable cause)
{
this(info, cause, null);
}

public PureExecutionException(SourceInformation sourceInformation, MutableStack<CoreInstance> callStack)
{
super(sourceInformation);
this.callStack = callStack;
}

public PureExecutionException(SourceInformation sourceInformation)
{
this(sourceInformation, (MutableStack<CoreInstance>) null);
}

public PureExecutionException(String info, MutableStack<CoreInstance> callStack)
{
super(info);
this.callStack = callStack;
}

public PureExecutionException(String info)
{
this(info, (MutableStack<CoreInstance>) null);
}

public PureExecutionException(Throwable cause, MutableStack<CoreInstance> callStack)
{
super(cause);
this.callStack = callStack;
}

public PureExecutionException(Throwable cause)
{
this(cause, null);
}

public PureExecutionException()
{
super();
this.callStack = null;
}

@Override
Expand All @@ -94,41 +127,25 @@ public MutableStack<CoreInstance> getCallStack()
public <T extends Appendable> 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<? super CoreInstance>)
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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,19 @@
/**
* Indicates that an exception was thrown while we were writing to the response
* during lazy streaming execution
*
* <p>
* 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<CoreInstance> callStack)
{
super(cause, callStack);
}
{
super(cause, callStack);
}

public PureExecutionStreamingException(Throwable cause)
{
super(cause);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,45 +14,44 @@

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;

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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.<org.finos.legend.pure.m4.coreinstance.CoreInstance>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" +

Expand All @@ -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.<org.finos.legend.pure.m4.coreinstance.CoreInstance>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;" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.<org.finos.legend.pure.m4.coreinstance.CoreInstance>empty());\n" : "") +
(Type.isBottomType(_class, processorSupport) ? " throw new org.finos.legend.pure.m3.exception.PureExecutionException(\"Cannot instantiate " + PackageableElement.getUserPathForPackageableElement(_class, "::") + "\");\n" : "") +
" }\n" +
"\n";
}
Expand Down Expand Up @@ -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.<org.finos.legend.pure.m4.coreinstance.CoreInstance>empty());\n" +
" throw new org.finos.legend.pure.m3.exception.PureExecutionException(sourceInformation, " + errorMessage + ");\n" +
" }\n";
}
else
Expand Down
Loading

0 comments on commit e53e242

Please sign in to comment.