Search in sources :

Example 1 with ExceptionType

use of com.oracle.truffle.api.interop.ExceptionType in project graal by oracle.

the class TruffleExceptionTest method testExceptionFromPolyglotExceptionConstructorImpl.

private void testExceptionFromPolyglotExceptionConstructorImpl(ExceptionType type, boolean internal, TruffleExceptionImpl.MessageKind... failOn) {
    setupEnv(Context.create(), new ProxyLanguage() {

        @Override
        protected CallTarget parse(TruffleLanguage.ParsingRequest request) throws Exception {
            ThrowNode throwNode = new ThrowNode((n) -> new TruffleExceptionImpl("test", n, type, new InjectException(failOn)));
            return new TestRootNode(languageInstance, "test", "unnamed", throwNode).getCallTarget();
        }
    });
    assertFails(() -> context.eval(ProxyLanguage.ID, "Test"), PolyglotException.class, (pe) -> {
        Assert.assertEquals(internal, pe.isInternalError());
    });
}
Also used : Arrays(java.util.Arrays) BeforeClass(org.junit.BeforeClass) AbstractTruffleException(com.oracle.truffle.api.exception.AbstractTruffleException) ExportLibrary(com.oracle.truffle.api.library.ExportLibrary) DirectCallNode(com.oracle.truffle.api.nodes.DirectCallNode) PolyglotException(org.graalvm.polyglot.PolyglotException) TruffleBoundary(com.oracle.truffle.api.CompilerDirectives.TruffleBoundary) InteropException(com.oracle.truffle.api.interop.InteropException) TruffleLogger(com.oracle.truffle.api.TruffleLogger) InvalidArrayIndexException(com.oracle.truffle.api.interop.InvalidArrayIndexException) TruffleStackTrace(com.oracle.truffle.api.TruffleStackTrace) ProxyLanguage(com.oracle.truffle.api.test.polyglot.ProxyLanguage) CompilerDirectives(com.oracle.truffle.api.CompilerDirectives) BranchProfile(com.oracle.truffle.api.profiles.BranchProfile) InteropLibrary(com.oracle.truffle.api.interop.InteropLibrary) RootNode(com.oracle.truffle.api.nodes.RootNode) SourceSection(com.oracle.truffle.api.source.SourceSection) EnumSet(java.util.EnumSet) TruffleTestAssumptions(com.oracle.truffle.tck.tests.TruffleTestAssumptions) Before(org.junit.Before) PrintWriter(java.io.PrintWriter) TruffleObject(com.oracle.truffle.api.interop.TruffleObject) Node(com.oracle.truffle.api.nodes.Node) UnsupportedMessageException(com.oracle.truffle.api.interop.UnsupportedMessageException) RootNodeTest.verifyStackTraceElementGuestObject(com.oracle.truffle.api.test.RootNodeTest.verifyStackTraceElementGuestObject) StringWriter(java.io.StringWriter) Set(java.util.Set) Test(org.junit.Test) VirtualFrame(com.oracle.truffle.api.frame.VirtualFrame) CallTarget(com.oracle.truffle.api.CallTarget) LogRecord(java.util.logging.LogRecord) ControlFlowException(com.oracle.truffle.api.nodes.ControlFlowException) Consumer(java.util.function.Consumer) AbstractPolyglotTest(com.oracle.truffle.api.test.polyglot.AbstractPolyglotTest) List(java.util.List) ExceptionType(com.oracle.truffle.api.interop.ExceptionType) ExplodeLoop(com.oracle.truffle.api.nodes.ExplodeLoop) ExportMessage(com.oracle.truffle.api.library.ExportMessage) TruffleStackTraceElement(com.oracle.truffle.api.TruffleStackTraceElement) Truffle(com.oracle.truffle.api.Truffle) Queue(java.util.Queue) Pattern(java.util.regex.Pattern) Context(org.graalvm.polyglot.Context) ArrayDeque(java.util.ArrayDeque) Handler(java.util.logging.Handler) Assert(org.junit.Assert) TruffleLanguage(com.oracle.truffle.api.TruffleLanguage) Collections(java.util.Collections) CallTarget(com.oracle.truffle.api.CallTarget) TruffleLanguage(com.oracle.truffle.api.TruffleLanguage) AbstractTruffleException(com.oracle.truffle.api.exception.AbstractTruffleException) PolyglotException(org.graalvm.polyglot.PolyglotException) InteropException(com.oracle.truffle.api.interop.InteropException) InvalidArrayIndexException(com.oracle.truffle.api.interop.InvalidArrayIndexException) UnsupportedMessageException(com.oracle.truffle.api.interop.UnsupportedMessageException) ControlFlowException(com.oracle.truffle.api.nodes.ControlFlowException) ProxyLanguage(com.oracle.truffle.api.test.polyglot.ProxyLanguage)

Example 2 with ExceptionType

use of com.oracle.truffle.api.interop.ExceptionType in project graal by oracle.

the class TruffleExceptionTest method testExceptionFromCreateContext.

@Test
public void testExceptionFromCreateContext() {
    String message = "Failed to create";
    ExceptionType type = ExceptionType.EXIT;
    assertFails(() -> setupEnv(Context.create(), new ProxyLanguage() {

        @Override
        protected LanguageContext createContext(Env env) {
            throw new TruffleExceptionImpl(message, null, type, null);
        }
    }), PolyglotException.class, (pe) -> {
        Assert.assertEquals(message, pe.getMessage());
        Assert.assertTrue(pe.isExit());
        Assert.assertFalse(pe.isInternalError());
        Assert.assertEquals(0, pe.getExitStatus());
        Assert.assertNull(pe.getGuestObject());
    });
}
Also used : ExceptionType(com.oracle.truffle.api.interop.ExceptionType) ProxyLanguage(com.oracle.truffle.api.test.polyglot.ProxyLanguage) Test(org.junit.Test) AbstractPolyglotTest(com.oracle.truffle.api.test.polyglot.AbstractPolyglotTest)

Aggregations

ExceptionType (com.oracle.truffle.api.interop.ExceptionType)2 AbstractPolyglotTest (com.oracle.truffle.api.test.polyglot.AbstractPolyglotTest)2 ProxyLanguage (com.oracle.truffle.api.test.polyglot.ProxyLanguage)2 CallTarget (com.oracle.truffle.api.CallTarget)1 CompilerDirectives (com.oracle.truffle.api.CompilerDirectives)1 TruffleBoundary (com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)1 Truffle (com.oracle.truffle.api.Truffle)1 TruffleLanguage (com.oracle.truffle.api.TruffleLanguage)1 TruffleLogger (com.oracle.truffle.api.TruffleLogger)1 TruffleStackTrace (com.oracle.truffle.api.TruffleStackTrace)1 TruffleStackTraceElement (com.oracle.truffle.api.TruffleStackTraceElement)1 AbstractTruffleException (com.oracle.truffle.api.exception.AbstractTruffleException)1 VirtualFrame (com.oracle.truffle.api.frame.VirtualFrame)1 InteropException (com.oracle.truffle.api.interop.InteropException)1 InteropLibrary (com.oracle.truffle.api.interop.InteropLibrary)1 InvalidArrayIndexException (com.oracle.truffle.api.interop.InvalidArrayIndexException)1 TruffleObject (com.oracle.truffle.api.interop.TruffleObject)1 UnsupportedMessageException (com.oracle.truffle.api.interop.UnsupportedMessageException)1 ExportLibrary (com.oracle.truffle.api.library.ExportLibrary)1 ExportMessage (com.oracle.truffle.api.library.ExportMessage)1