Skip to content

Commit f504e97

Browse files
committed
[GR-14735] Do not suppress the stacktrace of internal exceptions.
PullRequest: truffleruby/896
2 parents 46ed8cc + 42363b2 commit f504e97

File tree

6 files changed

+18
-22
lines changed

6 files changed

+18
-22
lines changed

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

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import org.graalvm.polyglot.Engine;
1717
import org.graalvm.polyglot.PolyglotException;
1818
import org.graalvm.polyglot.Source;
19+
import org.graalvm.polyglot.Value;
1920
import org.truffleruby.shared.options.OptionsCatalog;
2021
import org.truffleruby.shared.TruffleRuby;
2122
import org.truffleruby.shared.Metrics;
@@ -102,7 +103,7 @@ protected List<String> preprocessArguments(List<String> args, Map<String, String
102103
}
103104

104105
} catch (CommandLineException commandLineException) {
105-
System.err.println(TruffleRuby.SIMPLE_NAME + ": " + commandLineException.getMessage());
106+
System.err.println("truffleruby: " + commandLineException.getMessage());
106107
if (commandLineException.isUsageError()) {
107108
printHelp(System.err);
108109
}
@@ -171,7 +172,7 @@ protected void printHelp(OptionCategory maxCategory) {
171172
@Override
172173
protected AbortException abortUnrecognizedArgument(String argument) {
173174
throw abortInvalidArgument(argument,
174-
TruffleRuby.SIMPLE_NAME + ": invalid option " + argument + " (Use --help for usage instructions.)");
175+
"truffleruby: invalid option " + argument + " (Use --help for usage instructions.)");
175176
}
176177

177178
private int runRubyMain(Context.Builder contextBuilder, CommandLineOptions config) {
@@ -209,7 +210,13 @@ private int runRubyMain(Context.Builder contextBuilder, CommandLineOptions confi
209210
TruffleRuby.BOOT_SOURCE_NAME).internal(true).buildLiteral();
210211

211212
config.executionAction = ExecutionAction.FILE;
212-
config.toExecute = context.eval(source).execute(config.toExecute).asString();
213+
final Value file = context.eval(source).execute(config.toExecute);
214+
if (file.isString()) {
215+
config.toExecute = file.asString();
216+
} else {
217+
System.err.println("truffleruby: No such file or directory -- " + config.toExecute + " (LoadError)");
218+
return 1;
219+
}
213220
}
214221

215222
final Source source = Source.newBuilder(TruffleRuby.LANGUAGE_ID,
@@ -222,7 +229,7 @@ private int runRubyMain(Context.Builder contextBuilder, CommandLineOptions confi
222229
Metrics.printTime("after-run");
223230
return exitCode;
224231
} catch (PolyglotException e) {
225-
System.err.println(TruffleRuby.SIMPLE_NAME + ": " + e.getMessage());
232+
e.printStackTrace();
226233
return 1;
227234
}
228235
}

src/main/java/org/truffleruby/RubyLanguage.java

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import com.oracle.truffle.api.nodes.Node;
2222
import com.oracle.truffle.api.object.DynamicObject;
2323
import com.oracle.truffle.api.source.SourceSection;
24-
import org.graalvm.options.OptionDescriptor;
2524
import org.graalvm.options.OptionDescriptors;
2625
import org.truffleruby.cext.ValueWrapper;
2726
import org.truffleruby.core.kernel.TraceManager;
@@ -38,9 +37,8 @@
3837
import org.truffleruby.platform.Platform;
3938
import org.truffleruby.stdlib.CoverageManager;
4039

41-
import java.util.ArrayList;
40+
import java.util.Arrays;
4241
import java.util.Collections;
43-
import java.util.List;
4442

4543
@TruffleLanguage.Registration(
4644
name = "Ruby",
@@ -211,14 +209,7 @@ protected SourceSection findSourceLocation(RubyContext context, Object value) {
211209

212210
@Override
213211
protected OptionDescriptors getOptionDescriptors() {
214-
final OptionDescriptor[] allDescriptions = OptionsCatalog.allDescriptors();
215-
final List<OptionDescriptor> options = new ArrayList<>(allDescriptions.length);
216-
217-
for (OptionDescriptor descriptor : allDescriptions) {
218-
options.add(descriptor);
219-
}
220-
221-
return OptionDescriptors.create(options);
212+
return OptionDescriptors.create(Arrays.asList(OptionsCatalog.allDescriptors()));
222213
}
223214

224215
@Override

src/main/java/org/truffleruby/language/TruffleBootNodes.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ public abstract static class MainNode extends CoreMethodArrayArgumentsNode {
9595
@Specialization
9696
public int main(DynamicObject kind, DynamicObject toExecute,
9797
@Cached("create()") IndirectCallNode callNode,
98-
@Cached("createPrivate()") CallDispatchHeadNode findSFile,
9998
@Cached("createPrivate()") CallDispatchHeadNode checkSyntax,
10099
@Cached("create()") StringNodes.MakeStringNode makeStringNode) {
101100

@@ -105,7 +104,7 @@ public int main(DynamicObject kind, DynamicObject toExecute,
105104

106105
try {
107106
source = loadMainSourceSettingDollarZero(
108-
findSFile, makeStringNode,
107+
makeStringNode,
109108
StringOperations.getString(kind),
110109
StringOperations.getString(toExecute).intern());
111110
} catch (RaiseException e) {
@@ -170,7 +169,7 @@ private void setArgvGlobals(StringNodes.MakeStringNode makeStringNode) {
170169
}
171170
}
172171

173-
private RubySource loadMainSourceSettingDollarZero(CallDispatchHeadNode findSFile, StringNodes.MakeStringNode makeStringNode, String kind, String toExecute) {
172+
private RubySource loadMainSourceSettingDollarZero(StringNodes.MakeStringNode makeStringNode, String kind, String toExecute) {
174173
final RubySource source;
175174
final Object dollarZeroValue;
176175
try {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public void printRubyExceptionMessageOnEnvStderr(DynamicObject rubyException) {
102102
} else {
103103
messageString = message.toString();
104104
}
105-
printer.println(TruffleRuby.SIMPLE_NAME + ": " + messageString);
105+
printer.println("truffleruby: " + messageString);
106106
}
107107

108108
@TruffleBoundary

src/main/ruby/truffleruby/core/truffle/boot.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ def self.find_s_file(name)
4444
path = find_in_environment_paths(name, ENV['PATH']) and return path
4545
return name if File.exist?(name)
4646

47-
# Fail otherwise
48-
raise LoadError, "No such file or directory -- #{name}"
47+
# Not found, let the RubyLauncher print the error
48+
nil
4949
end
5050

5151
def self.find_in_environment_paths(name, env_value)

src/shared/java/org/truffleruby/shared/TruffleRuby.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
public class TruffleRuby {
1313

1414
public static final String FORMAL_NAME = "TruffleRuby";
15-
public static final String SIMPLE_NAME = "truffleruby";
1615
public static final String LANGUAGE_ID = "ruby";
1716
public static final String MIME_TYPE = "application/x-ruby";
1817
public static final String EXTENSION = ".rb";

0 commit comments

Comments
 (0)