Search in sources :

Example 1 with PureException

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());
}
Also used : PureException(org.finos.legend.pure.m4.exception.PureException) PureExecutionException(org.finos.legend.pure.m3.exception.PureExecutionException) SourceInformation(org.finos.legend.pure.m4.coreinstance.SourceInformation)

Example 2 with PureException

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());
}
Also used : PureException(org.finos.legend.pure.m4.exception.PureException) PureExecutionException(org.finos.legend.pure.m3.exception.PureExecutionException) SourceInformation(org.finos.legend.pure.m4.coreinstance.SourceInformation)

Example 3 with PureException

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());
}
Also used : PureException(org.finos.legend.pure.m4.exception.PureException) PureExecutionException(org.finos.legend.pure.m3.exception.PureExecutionException) SourceInformation(org.finos.legend.pure.m4.coreinstance.SourceInformation)

Example 4 with PureException

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;
}
Also used : PureException(org.finos.legend.pure.m4.exception.PureException) ProcessorSupport(org.finos.legend.pure.m3.navigation.ProcessorSupport) M3ProcessorSupport(org.finos.legend.pure.m3.navigation.M3ProcessorSupport) M3ProcessorSupport(org.finos.legend.pure.m3.navigation.M3ProcessorSupport) PureExecutionStreamingException(org.finos.legend.pure.m3.exception.PureExecutionStreamingException) PureExecutionException(org.finos.legend.pure.m3.exception.PureExecutionException) IOException(java.io.IOException) PureException(org.finos.legend.pure.m4.exception.PureException)

Example 5 with PureException

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());
    }
}
Also used : PureException(org.finos.legend.pure.m4.exception.PureException) M4Parser(org.finos.legend.pure.m4.serialization.grammar.M4Parser) VoidM4StateListener(org.finos.legend.pure.m4.statelistener.VoidM4StateListener) PureException(org.finos.legend.pure.m4.exception.PureException) PureCompilationException(org.finos.legend.pure.m4.exception.PureCompilationException) PureCompilationException(org.finos.legend.pure.m4.exception.PureCompilationException) Test(org.junit.Test)

Aggregations

PureException (org.finos.legend.pure.m4.exception.PureException)34 CoreInstance (org.finos.legend.pure.m4.coreinstance.CoreInstance)13 SourceInformation (org.finos.legend.pure.m4.coreinstance.SourceInformation)11 PureCompilationException (org.finos.legend.pure.m4.exception.PureCompilationException)10 PureExecutionException (org.finos.legend.pure.m3.exception.PureExecutionException)7 ProcessorSupport (org.finos.legend.pure.m3.navigation.ProcessorSupport)6 PureParserException (org.finos.legend.pure.m4.serialization.grammar.antlr.PureParserException)5 Test (org.junit.Test)4 IOException (java.io.IOException)3 PureCodeStorage (org.finos.legend.pure.m3.serialization.filesystem.PureCodeStorage)3 Parser (org.finos.legend.pure.m3.serialization.grammar.Parser)3 PureRuntime (org.finos.legend.pure.m3.serialization.runtime.PureRuntime)3 FileNotFoundException (java.io.FileNotFoundException)2 PrintWriter (java.io.PrintWriter)2 StringWriter (java.io.StringWriter)2 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)2 MojoFailureException (org.apache.maven.plugin.MojoFailureException)2 RichIterable (org.eclipse.collections.api.RichIterable)2 MutableList (org.eclipse.collections.api.list.MutableList)2 M3ProcessorSupport (org.finos.legend.pure.m3.navigation.M3ProcessorSupport)2