use of org.finos.legend.pure.m4.exception.PureException in project legend-pure by finos.
the class AbstractTestCast method checkInvalidCastWithTypeParametersErrorMessage.
public void checkInvalidCastWithTypeParametersErrorMessage(Exception e) {
PureException pe = PureException.findPureException(e);
Assert.assertNotNull(pe);
Assert.assertTrue(pe instanceof PureExecutionException);
Assert.assertEquals("Cast exception: List<X> cannot be cast to List<Y>", pe.getInfo());
SourceInformation sourceInfo = pe.getSourceInformation();
Assert.assertNotNull(sourceInfo);
Assert.assertEquals(3, sourceInfo.getLine());
Assert.assertEquals(49, sourceInfo.getColumn());
}
use of org.finos.legend.pure.m4.exception.PureException in project legend-pure by finos.
the class AbstractTestCast method checkCastErrorMessage.
public void checkCastErrorMessage(Exception e) {
PureException pe = PureException.findPureException(e);
Assert.assertNotNull(pe);
Assert.assertTrue(pe instanceof PureExecutionException);
PureException originalPE = pe.getOriginatingPureException();
Assert.assertNotNull(originalPE);
Assert.assertTrue(originalPE instanceof PureExecutionException);
Assert.assertEquals("Cast exception: A cannot be cast to C", originalPE.getInfo());
SourceInformation sourceInfo = originalPE.getSourceInformation();
Assert.assertNotNull(sourceInfo);
Assert.assertEquals(7, sourceInfo.getLine());
Assert.assertEquals(25, sourceInfo.getColumn());
}
use of org.finos.legend.pure.m4.exception.PureException in project legend-pure by finos.
the class AbstractTestCast method checkInvalidTypeCastErrorMessage.
public void checkInvalidTypeCastErrorMessage(Exception e, String message, int line, int column) {
PureException pe = PureException.findPureException(e);
Assert.assertNotNull(pe);
Assert.assertTrue(pe instanceof PureExecutionException);
Assert.assertEquals(message, pe.getInfo());
SourceInformation sourceInfo = pe.getSourceInformation();
Assert.assertNotNull(sourceInfo);
Assert.assertEquals(line, sourceInfo.getLine());
Assert.assertEquals(column, sourceInfo.getColumn());
}
use of org.finos.legend.pure.m4.exception.PureException in project legend-pure by finos.
the class FunctionExecutionCompiled method executeFunction.
private Object executeFunction(CoreInstance functionDefinition, ListIterable<? extends CoreInstance> arguments, CompiledExecutionSupport executionSupport) {
ProcessorSupport processorSupport = new M3ProcessorSupport(this.context, this.repository);
Object result;
try {
result = this.executeFunction(functionDefinition, arguments, executionSupport, this.javaCompilerEventHandler.getJavaCompiler().getClassLoader(), processorSupport);
} catch (PureException pe) {
// Rethrow as is to keep the original error
throw pe;
} catch (Exception e) {
StringBuilder builder = new StringBuilder("Error executing ");
try {
org.finos.legend.pure.m3.navigation.function.Function.print(builder, functionDefinition, processorSupport);
} catch (Exception ignore) {
builder = new StringBuilder("Error executing ");
builder.append(functionDefinition);
}
builder.append(". ");
if (e.getMessage() != null) {
builder.append(e.getMessage());
}
throw new RuntimeException(builder.toString(), e);
}
if (result == null) {
result = Lists.immutable.empty();
}
return result;
}
use of org.finos.legend.pure.m4.exception.PureException in project legend-pure by finos.
the class TestCoreM4 method testReferentialIntegrity.
@Test
public void testReferentialIntegrity() {
ModelRepository repository = new ModelRepository();
try {
new M4Parser().parse("^Class Class\n" + "{\n" + " Element.properties[name] : 'Class'\n" + "}\n" + "^Class String" + "{" + "}\n" + "^Class Element\n" + "{\n" + " Element.properties[name] : 'Element',\n" + " Class.properties[properties] :\n" + " [\n" + " ^Property name\n" + " {\n" + " Property.properties[type] : String\n" + " }\n" + " ]\n" + "}\n", repository, new VoidM4StateListener());
Assert.assertEquals("Class_0 instance Class_0\n" + " name_6(Property_5):\n" + " Class_2 instance String_1", repository.getTopLevel("Class").printFull(""));
try {
repository.getTopLevel("Element").printFull("");
Assert.fail();
} catch (Exception e) {
Assert.assertEquals("Error resolving path [Class, properties, properties]: 'properties' is unknown for the key 'properties' in 'Class'", e.getMessage());
}
repository.validate(new VoidM4StateListener());
Assert.fail();
} catch (Exception e) {
PureException pe = PureException.findPureException(e);
Assert.assertNotNull(pe);
Assert.assertTrue(pe instanceof PureCompilationException);
Assert.assertEquals("Property has not been defined!", pe.getInfo());
}
}
Aggregations