Skip to content

Conversation

@graalvmbot
Copy link
Collaborator

This pull request adds support for stack traces of foreign Truffle exceptions hosted in an isolated heap.
To enable this, all stack frame operations must use the interop protocol so they can be forwarded into the polyglot isolate.

Examples:
Host object:

public final class HostApi {

    public HostApi() {
    }

    public void execute() {
        executeImpl();
    }

    private void executeImpl() {
        fail();
    }

    private void fail() {
        throw new IllegalStateException("Not supported");
    }

    public void call(Value callback) {
        callback.execute();
    }
}

Isolated JavaScript snippets with corresponding stack traces:
Guest language exception:

function main() {
        outer();
    }
    
    function outer() {
        inner();
    }
    
    function inner() {
        fail();
    }
    
    function fail() {
        throw Error('Test exception')
    }

    main()

Stack trace:

Error: Error: Test exception
        at <js> fail(Unnamed:14:131-153)
        at <js> inner(Unnamed:10:92-97)
        at <js> outer(Unnamed:6:57-63)
        at <js> main(Unnamed:2:22-28)
        at <js> :program(Unnamed:17:158-163)
        at org.graalvm.polyglot.Context.eval(Context.java:1)
        at org.me.Main.testJavaScriptException(Main.java:1)
        at org.me.Main.main(Main.java:1

Host languge exception:

HostApi = Java.type('org.me.HostApi')
    api = new HostApi()
    
    function main() {
        outer();
    }
    
    function outer() {
        inner();
    }
    
    function inner() {
        api.execute()
    }

    main()

Stack trace:

java.lang.IllegalStateException: Not supported
        at org.me.HostApi.fail(HostApi.java:1)
        at org.me.HostApi.executeImpl(HostApi.java:1)
        at org.me.HostApi.execute(HostApi.java:1)
        at <js> inner(Unknown)
        at <js> outer(Unnamed:9:116-122)
        at <js> main(Unnamed:5:81-87)
        at <js> :program(Unnamed:16:168-173)
        at org.graalvm.polyglot.Context.eval(Context.java:1)
        at org.me.Main.testJavaScriptHostException(Main.java:1)
        at org.me.Main.main(Main.java:1

Host language exception with interleaved host-guest calls.

HostApi = Java.type('org.me.HostApi')
    api = new HostApi()
    
    function main() {
        outer();
    }
    
    function outer() {
        inner();
    }
    
    function inner() {
        api.call(callback)
    }
    
    function callback() {
        api.execute()
    }

    main()

Stack trace:

java.lang.IllegalStateException: Not supported
        at org.me.HostApi.fail(HostApi.java:1)
        at org.me.HostApi.executeImpl(HostApi.java:1)
        at org.me.HostApi.execute(HostApi.java:1)
        at <js> callback(Unknown)
        at org.graalvm.polyglot.Value.execute(Value.java:1)
        at org.me.HostApi.call(HostApi.java:1)
        at <js> inner(Unknown)
        at <js> outer(Unnamed:9:116-122)
        at <js> main(Unnamed:5:81-87)
        at <js> :program(Unnamed:20:216-221)
        at org.graalvm.polyglot.Context.eval(Context.java:1)
        at org.me.Main.testJavaScriptHostException2(Main.java:1)
        at org.me.Main.main(Main.java:1)

@oracle-contributor-agreement oracle-contributor-agreement bot added the OCA Verified All contributors have signed the Oracle Contributor Agreement. label Oct 7, 2025
@graalvmbot graalvmbot force-pushed the tzezula/polyglot_isolate_exceptions branch from 6cd2141 to d56294c Compare December 15, 2025 15:03
@graalvmbot graalvmbot force-pushed the tzezula/polyglot_isolate_exceptions branch from 89b3558 to a67b4e2 Compare December 15, 2025 17:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

OCA Verified All contributors have signed the Oracle Contributor Agreement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants