Skip to content

Commit ad09f80

Browse files
committed
[GR-63778] A language with id regex is not installed, Installed languages are: regex.
PullRequest: graal/20460
2 parents 8775535 + 44f59cf commit ad09f80

File tree

6 files changed

+74
-10
lines changed

6 files changed

+74
-10
lines changed

truffle/src/com.oracle.truffle.api.instrumentation.test/src/com/oracle/truffle/api/instrumentation/test/TruffleContextTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,7 @@ public void testEvalInnerContextEvalErrors() {
574574
innerContext.leave(null, prev);
575575

576576
assertFails(() -> innerContext.evalInternal(null, com.oracle.truffle.api.source.Source.newBuilder("foobarbazz$_", "", "").build()), IllegalArgumentException.class, (e) -> {
577-
assertTrue(e.getMessage(), e.getMessage().startsWith("A language with id 'foobarbazz$_' is not installed. Installed languages are:"));
577+
assertTrue(e.getMessage(), e.getMessage().startsWith("A language with id 'foobarbazz$_' is not available. Available languages are:"));
578578
});
579579
innerContext.close();
580580
}

truffle/src/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/polyglot/ContextAPITest.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
import java.util.concurrent.atomic.AtomicInteger;
7676
import java.util.concurrent.atomic.AtomicReference;
7777

78+
import com.oracle.truffle.api.test.common.TestUtils;
7879
import org.graalvm.options.OptionCategory;
7980
import org.graalvm.options.OptionDescriptors;
8081
import org.graalvm.options.OptionKey;
@@ -1378,4 +1379,25 @@ public void testPermittedLanguages() {
13781379

13791380
}
13801381

1382+
@Test
1383+
public void testGR63778() {
1384+
try (Context c = Context.create()) {
1385+
assertFails(() -> c.eval(TestUtils.getDefaultLanguageId(TestGR63778Internal.class), ""),
1386+
IllegalArgumentException.class,
1387+
(ia) -> {
1388+
String message = ia.getMessage();
1389+
assertTrue(message.contains(" language with id '" + TestUtils.getDefaultLanguageId(TestGR63778Internal.class) + "' is not available."));
1390+
assertTrue(message.contains("A language with this id is installed, but only available internally."));
1391+
});
1392+
}
1393+
}
1394+
1395+
@TruffleLanguage.Registration(internal = true)
1396+
static class TestGR63778Internal extends AbstractExecutableTestLanguage {
1397+
1398+
@Override
1399+
protected Object execute(RootNode node, Env env, Object[] contextArguments, Object[] frameArguments) throws Exception {
1400+
return null;
1401+
}
1402+
}
13811403
}

truffle/src/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/polyglot/ContextPolyglotAccessTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ public void testNotExistingEmbedder() {
185185
context.initialize(NOT_EXISTING_LANGUAGE);
186186
fail();
187187
} catch (IllegalArgumentException e) {
188-
assertTrue(e.getMessage(), e.getMessage().startsWith("A language with id '" + NOT_EXISTING_LANGUAGE + "' is not installed."));
188+
assertTrue(e.getMessage(), e.getMessage().startsWith("A language with id '" + NOT_EXISTING_LANGUAGE + "' is not available."));
189189
}
190190

191191
evalTestLanguage(context, NotExistingEmbedderTestLanguage.class, "");

truffle/src/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/polyglot/LanguageSPITest.java

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1563,6 +1563,42 @@ protected Object execute(RootNode node, Env env, Object[] contextArguments, Obje
15631563
}
15641564
}
15651565

1566+
@Test
1567+
public void testGR63778() {
1568+
try (Context context = Context.create()) {
1569+
execute(context, TestGR63778Language.class);
1570+
}
1571+
}
1572+
1573+
@TruffleLanguage.Registration
1574+
static class TestGR63778Language extends AbstractExecutableTestLanguage {
1575+
1576+
@Override
1577+
@TruffleBoundary
1578+
protected Object execute(RootNode node, Env env, Object[] contextArguments, Object[] frameArguments) throws Exception {
1579+
try (TruffleContext truffleContext = env.newInnerContextBuilder().build();) {
1580+
Source source = Source.newBuilder(TestUtils.getDefaultLanguageId(TestGR63778Internal.class), "", "source").build();
1581+
assertFails(() -> truffleContext.evalPublic(null, source),
1582+
IllegalArgumentException.class,
1583+
(ia) -> {
1584+
String message = ia.getMessage();
1585+
assertTrue(message.contains(" language with id '" + TestUtils.getDefaultLanguageId(TestGR63778Internal.class) + "' is not available."));
1586+
assertTrue(message.contains("A language with this id is installed, but only available internally."));
1587+
});
1588+
return null;
1589+
}
1590+
}
1591+
}
1592+
1593+
@TruffleLanguage.Registration(internal = true)
1594+
static class TestGR63778Internal extends AbstractExecutableTestLanguage {
1595+
1596+
@Override
1597+
protected Object execute(RootNode node, Env env, Object[] contextArguments, Object[] frameArguments) throws Exception {
1598+
return null;
1599+
}
1600+
}
1601+
15661602
@Test
15671603
public void testInnerContextPermittedLanguages() {
15681604
try (Context context = Context.create()) {

truffle/src/com.oracle.truffle.polyglot/src/com/oracle/truffle/polyglot/PolyglotContextImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1911,8 +1911,8 @@ public Object eval(String languageId, Object source) {
19111911
}
19121912

19131913
public PolyglotLanguage requirePublicLanguage(String languageId) {
1914-
PolyglotLanguage language = engine.idToLanguage.get(languageId);
1915-
if (language == null || language.cache.isInternal()) {
1914+
PolyglotLanguage language = engine.idToPublicLanguage.get(languageId);
1915+
if (language == null) {
19161916
engine.requireLanguage(languageId, false); // will trigger the error
19171917
assert false;
19181918
return null;

truffle/src/com.oracle.truffle.polyglot/src/com/oracle/truffle/polyglot/PolyglotEngineImpl.java

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1176,25 +1176,31 @@ void reportAllContextThreads(ThreadsListener listener) {
11761176

11771177
PolyglotLanguage requireLanguage(String id, boolean allowInternal) {
11781178
checkState();
1179-
PolyglotLanguage language;
1179+
Map<String, PolyglotLanguage> useLanguages;
11801180
if (allowInternal) {
1181-
language = idToLanguage.get(id);
1181+
useLanguages = idToLanguage;
11821182
} else {
1183-
language = idToPublicLanguage.get(id);
1183+
useLanguages = idToPublicLanguage;
11841184
}
1185+
PolyglotLanguage language = useLanguages.get(id);
11851186
if (language == null) {
1186-
throw throwNotInstalled(id, idToLanguage.keySet());
1187+
throw throwNotInstalled(id, useLanguages.keySet());
11871188
}
11881189
return language;
11891190
}
11901191

1191-
private static RuntimeException throwNotInstalled(String id, Set<String> allLanguages) {
1192+
private RuntimeException throwNotInstalled(String id, Set<String> allLanguages) {
11921193
String misspelledGuess = matchSpellingError(allLanguages, id);
11931194
String didYouMean = "";
11941195
if (misspelledGuess != null) {
11951196
didYouMean = String.format("Did you mean '%s'? ", misspelledGuess);
11961197
}
1197-
throw PolyglotEngineException.illegalArgument(String.format("A language with id '%s' is not installed. %sInstalled languages are: %s.", id, didYouMean, allLanguages));
1198+
String internalLanguageHint = "";
1199+
if (idToLanguage.containsKey(id)) {
1200+
// no access to internal, but internal language available
1201+
internalLanguageHint = "A language with this id is installed, but only available internally. ";
1202+
}
1203+
throw PolyglotEngineException.illegalArgument(String.format("A language with id '%s' is not available. %s%sAvailable languages are: %s.", id, didYouMean, internalLanguageHint, allLanguages));
11981204
}
11991205

12001206
private static String matchSpellingError(Set<String> allIds, String enteredId) {

0 commit comments

Comments
 (0)