Skip to content

Commit 8c5ead7

Browse files
committed
[GR-44053] HostException#getExceptionStackTrace works now, remove workarounds
PullRequest: truffleruby/3715
2 parents a9bb95e + 55edf4d commit 8c5ead7

File tree

4 files changed

+22
-14
lines changed

4 files changed

+22
-14
lines changed

spec/truffle/interop/polyglot/foreign_exception_spec.rb

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,29 @@
2929
it "supports #full_message" do
3030
-> {
3131
raise @foreign
32-
}.should raise_error(Polyglot::ForeignException) {
33-
full_message = @foreign.full_message(highlight: false, order: :top).lines
32+
}.should raise_error(Polyglot::ForeignException) { |e|
33+
full_message = e.full_message(highlight: false, order: :top).lines
3434
full_message[0].should == "#{__FILE__}:#{__LINE__-3}:in `Kernel#raise': exception message (Polyglot::ForeignException)\n"
3535
}
3636
end
3737

38+
guard -> { !TruffleRuby.native? } do
39+
it "supports #full_message for a host exception" do
40+
integer = Java.type("java.lang.Integer")
41+
-> {
42+
integer.parseInt("abc")
43+
}.should raise_error(Polyglot::ForeignException) { |e|
44+
full_message = e.full_message(highlight: false, order: :top).gsub(/:\d+:/, ':LINE:')
45+
full_message.should.start_with?(<<~EXCEPTION)
46+
NumberFormatException.java:LINE:in `forInputString': For input string: "abc" (Polyglot::ForeignException: java.lang.NumberFormatException)
47+
\tfrom Integer.java:LINE:in `parseInt'
48+
\tfrom Integer.java:LINE:in `parseInt'
49+
\tfrom #{__FILE__ }:LINE:in `block (4 levels) in <top (required)>'
50+
EXCEPTION
51+
}
52+
end
53+
end
54+
3855
it "supports rescue Polyglot::ForeignException" do
3956
begin
4057
raise @foreign

spec/truffle/interop/polyglot/inner_context_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060

6161
-> { context.eval('ruby', '42') }.should raise_error(RuntimeError, 'This Polyglot::InnerContext is closed')
6262

63-
# obj.object_id # throws a host exception, but those currently cannot be caught due to the workaround for GR-22071
63+
# obj.object_id # throws a IllegalStateException which cannot be caught: GR-45031
6464
end
6565

6666
it "raises ArgumentError for an unknown language" do

src/launcher/java/org/truffleruby/launcher/RubyLauncher.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -309,12 +309,8 @@ private int runContext(Context.Builder builder, CommandLineOptions config) {
309309
Metrics.printTime("after-run");
310310
return exitCode;
311311
} catch (PolyglotException e) {
312-
if (e.isHostException()) { // GR-22071
313-
getError().println("truffleruby: a host exception reached the top level:");
314-
} else {
315-
getError().println(
316-
"truffleruby: an exception escaped out of the interpreter - this is an implementation bug");
317-
}
312+
getError().println(
313+
"truffleruby: an exception escaped out of the interpreter - this is an implementation bug");
318314
e.printStackTrace();
319315
return 1;
320316
}

src/main/java/org/truffleruby/language/backtrace/BacktraceFormatter.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -377,11 +377,6 @@ public static String formatJavaThrowableMessage(Throwable t) {
377377

378378
@TruffleBoundary
379379
public static void printInternalError(RubyContext context, Throwable throwable, String from) {
380-
if (context.getEnv().isHostException(throwable)) {
381-
// rethrow host exceptions to get the interleaved host and guest stacktrace of PolyglotException
382-
throw ExceptionOperations.rethrow(throwable);
383-
}
384-
385380
final PrintStream stream = context.getEnvErrStream();
386381
final BacktraceFormatter formatter = context.getDefaultBacktraceFormatter();
387382
stream.println();

0 commit comments

Comments
 (0)