Skip to content

Commit f82ad90

Browse files
committed
Fix TestSuite.getDetailedCause should work with PolyglotException.
(cherry picked from commit 79e8720)
1 parent 56ac119 commit f82ad90

File tree

1 file changed

+15
-10
lines changed
  • graal-js/src/com.oracle.truffle.js.test.external/src/com/oracle/truffle/js/test/external/suite

1 file changed

+15
-10
lines changed

graal-js/src/com.oracle.truffle.js.test.external/src/com/oracle/truffle/js/test/external/suite/TestSuite.java

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* The Universal Permissive License (UPL), Version 1.0
@@ -80,13 +80,11 @@
8080
import java.util.stream.Stream;
8181

8282
import org.graalvm.polyglot.Engine;
83+
import org.graalvm.polyglot.PolyglotException;
84+
import org.graalvm.polyglot.Value;
8385

8486
import com.oracle.truffle.js.runtime.JSConfig;
8587
import com.oracle.truffle.js.runtime.JSContextOptions;
86-
import com.oracle.truffle.js.runtime.Strings;
87-
import com.oracle.truffle.js.runtime.UserScriptException;
88-
import com.oracle.truffle.js.runtime.objects.JSDynamicObject;
89-
import com.oracle.truffle.js.runtime.objects.JSObject;
9088

9189
public abstract class TestSuite {
9290

@@ -533,11 +531,18 @@ public final void logFail(TestFile testFile, String failMessage, Throwable cause
533531
}
534532

535533
private static String getDetailedCause(Throwable cause) {
536-
if (cause instanceof UserScriptException) {
537-
UserScriptException use = (UserScriptException) cause;
538-
Object exceptionObject = use.getErrorObject();
539-
if (exceptionObject instanceof JSDynamicObject) {
540-
return String.valueOf(JSObject.get((JSDynamicObject) exceptionObject, Strings.MESSAGE));
534+
if (cause instanceof PolyglotException polyglotException) {
535+
Value guestObject = polyglotException.getGuestObject();
536+
if (guestObject != null) {
537+
try {
538+
if (guestObject.hasMembers()) {
539+
Value message = guestObject.getMember("message");
540+
if (message != null) {
541+
return message.toString();
542+
}
543+
}
544+
} catch (Exception ignored) {
545+
}
541546
}
542547
}
543548
return "";

0 commit comments

Comments
 (0)